ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zquest.cpp
Date: 2025-12-29 22:15:04
Exec Total Coverage
Lines: 1961 13175 14.9%
Functions: 44 669 6.6%
Branches: 1112 10048 11.1%

Line Branch Exec Source
1 #include "allegro/gui.h"
2 #include "base/files.h"
3 #include "base/mapscr.h"
4 #include "dialog/edit_region.h"
5
6 #include <memory>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <cstring>
10 #include <sstream>
11 #include <ctype.h>
12 #include <assert.h>
13 #include <time.h>
14 #include <vector>
15 #include <filesystem>
16 #include <base/new_menu.h>
17
18 #include "dialog/info_lister.h"
19 #include "zq/commands.h"
20 #include "zq/render_map_view.h"
21 #ifdef __APPLE__
22 // malloc.h is deprecated, but malloc also lives in stdlib
23 #include <stdlib.h>
24 #else
25 #include <malloc.h>
26 #endif
27
28 #include "zalleg/zalleg.h"
29 #include "base/qrs.h"
30 #include "base/dmap.h"
31 #include "base/msgstr.h"
32 #include "base/packfile.h"
33 #include "base/cpool.h"
34 #include "base/autocombo.h"
35 #include "base/render.h"
36 #include "base/version.h"
37 #include "zq/autocombo/autopattern_base.h"
38 #include "zq/autocombo/pattern_basic.h"
39 #include "zq/autocombo/pattern_flatmtn.h"
40 #include "zq/autocombo/pattern_fence.h"
41 #include "zq/autocombo/pattern_cakemtn.h"
42 #include "zq/autocombo/pattern_relational.h"
43 #include "zq/autocombo/pattern_dungeoncarve.h"
44 #include "zq/autocombo/pattern_dormtn.h"
45 #include "zq/autocombo/pattern_tiling.h"
46 #include "zq/autocombo/pattern_replace.h"
47 #include "zq/autocombo/pattern_denseforest.h"
48 #include "zq/autocombo/pattern_extend.h"
49 #include "zq/render_hotkeys.h"
50 #include "zq/render_minimap.h"
51 #include "zq/render_tooltip.h"
52 #include "base/misctypes.h"
53 #include "parser/Compiler.h"
54 #include "base/zc_alleg.h"
55 #include "particles.h"
56 #include "dialog/combopool.h"
57 #include "dialog/alertfunc.h"
58 #include "zq/gui/edit_autocombo.h"
59
60 #include <al5_img.h>
61 #include <loadpng.h>
62 #include <fmt/format.h>
63
64 #include "dialog/cheat_codes.h"
65 #include "dialog/set_password.h"
66 #include "dialog/quest_rules.h"
67 #include "dialog/script_rules.h"
68 #include "dialog/headerdlg.h"
69 #include "dialog/ffc_editor.h"
70 #include "dialog/screen_data.h"
71 #include "dialog/edit_dmap.h"
72 #include "dialog/compilezscript.h"
73 #include "dialog/screen_enemies.h"
74 #include "dialog/enemypattern.h"
75 #include "dialog/sfxdata.h"
76 #include "dialog/mapstyles.h"
77 #include "dialog/externs.h"
78
79 #include "base/gui.h"
80 #include "gui/jwin_a5.h"
81 #include "gui/jwin.h"
82 #include "zc_list_data.h"
83 #include "gui/editbox.h"
84 #include "zq/zq_misc.h"
85 #include "zq/zq_tiles.h" // tile and combo code
86
87 #include "zq/zquest.h"
88 #include "zq/ffasm.h"
89 #include "zq/render.h"
90
91 // the following are used by both zelda.cc and zquest.cc
92 #include "base/zdefs.h"
93 #include "base/qrs.h"
94 #include "tiles.h"
95 #include "base/colors.h"
96 #include "base/qst.h"
97 #include "base/zsys.h"
98 #include "base/zapp.h"
99 #include "base/process_management.h"
100 #include "play_midi.h"
101 #include "sound/zcmusic.h"
102
103 #include "midi.h"
104 #include "sprite.h"
105 #include "fontsdat.h"
106 #include "base/jwinfsel.h"
107 #include "zq/zq_class.h"
108 #include "subscr.h"
109 #include "zq/zq_subscr.h"
110 #include "zc/ffscript.h"
111 #include "gui/EditboxNew.h"
112 #include "sfx.h"
113 #include "zq/zq_custom.h" // custom items and guys
114 #include "zq/zq_strings.h"
115 #include "zq/questReport.h"
116 #include <fstream>
117 #include "drawing.h"
118 #include "zconsole/ConsoleLogger.h"
119 #include "colorname.h"
120 #include "zq/zq_hotkey.h"
121 #include "zq/package.h"
122 #include "zq/zq_files.h"
123 #include "music_playback.h"
124
125 //Windows mmemory tools
126 #ifdef _WIN32
127 #include <windows.h>
128 #include <stdio.h>
129 #include <psapi.h>
130 #pragma comment(lib, "psapi.lib") // Needed to avoid linker issues. -Z
131 #endif
132
133 #ifdef __EMSCRIPTEN__
134 #include <emscripten/emscripten.h>
135 #endif
136
137 #define MIDI_TRACK_BUFFER_SIZE 50
138 extern CConsoleLoggerEx parser_console;
139
140 using ZScript::disassembled_script_data;
141 void write_script(vector<shared_ptr<ZScript::Opcode>> const& zasm, string& dest,
142 bool commented, map<string,disassembled_script_data>* scr_meta_map);
143
144 namespace fs = std::filesystem;
145
146 #if defined(ALLEGRO_WINDOWS)
147 static const char *data_path_name = "win_data_path";
148 static const char *midi_path_name = "win_midi_path";
149 static const char *image_path_name = "win_image_path";
150 static const char *tmusic_path_name = "win_tmusic_path";
151 static const char *last_quest_name = "win_last_quest";
152 static const char *qtname_name = "win_qtname%d";
153 static const char *qtpath_name = "win_qtpath%d";
154 #elif defined(ALLEGRO_LINUX)
155 static const char *data_path_name = "linux_data_path";
156 static const char *midi_path_name = "linux_midi_path";
157 static const char *image_path_name = "linux_image_path";
158 static const char *tmusic_path_name = "linux_tmusic_path";
159 static const char *last_quest_name = "linux_last_quest";
160 static const char *qtname_name = "linux_qtname%d";
161 static const char *qtpath_name = "linux_qtpath%d";
162 #elif defined(__APPLE__)
163 static const char *data_path_name = "macosx_data_path";
164 static const char *midi_path_name = "macosx_midi_path";
165 static const char *image_path_name = "macosx_image_path";
166 static const char *tmusic_path_name = "macosx_tmusic_path";
167 static const char *last_quest_name = "macosx_last_quest";
168 static const char *qtname_name = "macosx_qtname%d";
169 static const char *qtpath_name = "macosx_qtpath%d";
170 #endif
171
172 #include "base/win32.h"
173
174 #include "zq/zq_init.h"
175 #include "zq/zq_doors.h"
176 #include "zq/zq_cset.h"
177 #include "zinfo.h"
178
179 #ifdef _MSC_VER
180 #include <crtdbg.h>
181
182 #endif
183
184 // MSVC fix
185 #if _MSC_VER >= 1900
186 FILE _iob[] = { *stdin, *stdout, *stderr };
187 extern "C" FILE * __cdecl __iob_func(void) { return _iob; }
188 #endif
189
190 extern byte monochrome_console;
191
192 #include "zconsole/ConsoleLogger.h"
193
194 extern CConsoleLoggerEx zscript_coloured_console;
195
196 uint8_t console_is_open = 0;
197 bool is_zq_replay_test = false;
198
199 #include "base/util.h"
200
201 #ifdef __EMSCRIPTEN__
202 #include "base/emscripten_utils.h"
203 #endif
204
205 using namespace util;
206
207 using std::vector;
208 using std::map;
209 using std::stringstream;
210
211 12 FFScript FFCore;
212
213 void load_size_poses();
214 void do_previewtext();
215 bool do_slots(vector<shared_ptr<ZScript::Opcode>> const& zasm,
216 map<string, disassembled_script_data> &scripts, int assign_mode);
217
218 int32_t tooltip_timer=0, tooltip_maxtimer=30, tooltip_current_ffc=0;
219 int32_t combobrushoverride=-1;
220 ComboPosition mouse_combo_pos;
221
222 int32_t original_playing_field_offset=0;
223 12 int32_t playing_field_offset=original_playing_field_offset;
224 int32_t passive_subscreen_height=56;
225
226 bool disable_saving=false, OverwriteProtection;
227 bool halt=false;
228 bool show_sprites=true;
229 bool show_hitboxes = false;
230 bool zq_ignore_item_ownership = true;
231
232 // Used to find FFC script names
233 vector<string> asffcscripts;
234 vector<string> asglobalscripts;
235 vector<string> asitemscripts;
236 vector<string> asnpcscripts;
237 vector<string> aseweaponscripts;
238 vector<string> aslweaponscripts;
239 vector<string> asplayerscripts;
240 vector<string> asdmapscripts;
241 vector<string> asscreenscripts;
242 vector<string> asitemspritescripts;
243 vector<string> ascomboscripts;
244 vector<string> asgenericscripts;
245 vector<string> assubscreenscripts;
246
247 vector<string> ZQincludePaths;
248
249 int32_t CSET_SIZE = 16;
250 int32_t CSET_SHFT = 4;
251 //editbox_data temp_eb_data;
252 /*
253 #define CSET(x) ((x)<<CSET_SHFT)
254 #define csBOSS 14
255 */
256
257 /*
258 enum { m_block, m_coords, m_flags, m_guy, m_warp, m_misc, m_layers,
259 m_menucount };
260 */
261 void update_combo_cycling();
262 void update_freeform_combos();
263
264 /*
265 #define MAXMICE 14
266 #define MAXARROWS 8
267 #define SHADOW_DEPTH 2
268 */
269 int32_t coord_timer=0, coord_frame=0;
270 int32_t blackout_color, zq_screen_w, zq_screen_h;
271 int32_t draw_mode=0;
272
273 12 size_and_pos minimap;
274 12 size_and_pos real_minimap;
275
276 12 size_and_pos minimap_zoomed;
277 12 size_and_pos real_minimap_zoomed;
278
279 12 size_and_pos map_page_bar[9];
280 int32_t mappage_count = 9;
281
282 12 size_and_pos combolist[MAX_COMBO_COLS];
283 12 size_and_pos combolistscrollers[MAX_COMBO_COLS];
284 int32_t num_combo_cols = MAX_COMBO_COLS;
285
286 static bool zoom_in_btn_disabled;
287 static bool zoom_out_btn_disabled;
288 12 size_and_pos zoominbtn;
289 12 size_and_pos zoomoutbtn;
290 12 size_and_pos compactbtn;
291 12 size_and_pos mainbar;
292
293 12 size_and_pos screrrorpos;
294
295 12 size_and_pos comboaliaslist[MAX_COMBO_COLS];
296 12 size_and_pos comboalias_preview;
297 12 size_and_pos combopool_preview;
298 12 size_and_pos combopool_prevbtn;
299
300 12 size_and_pos combo_merge_btn;
301
302 12 size_and_pos combo_preview;
303 12 size_and_pos combo_preview2;
304 12 size_and_pos combo_preview_text1;
305 12 size_and_pos combo_preview_text2;
306 12 size_and_pos combolist_window;
307 12 size_and_pos drawmode_btn;
308 12 size_and_pos main_panel;
309 12 size_and_pos squares_panel;
310 12 size_and_pos preview_panel;
311 12 size_and_pos layer_panel;
312 12 size_and_pos preview_text;
313
314 12 size_and_pos favorites_window;
315 12 size_and_pos favorites_list;
316 12 size_and_pos favorites_x;
317 12 size_and_pos favorites_infobtn;
318 12 size_and_pos favorites_zoombtn;
319 12 size_and_pos favorites_pgleft;
320 12 size_and_pos favorites_pgright;
321
322 12 size_and_pos commands_window;
323 12 size_and_pos commands_list;
324 12 size_and_pos commands_x;
325 12 size_and_pos commands_infobtn;
326 12 size_and_pos commands_zoombtn;
327 12 size_and_pos commands_txt;
328
329 12 size_and_pos squarepanel_swap_btn;
330 12 size_and_pos squarepanel_up_btn;
331 12 size_and_pos squarepanel_down_btn;
332 12 size_and_pos itemsqr_pos;
333 12 size_and_pos flagsqr_pos;
334 12 size_and_pos stairsqr_pos;
335 12 size_and_pos warparrival_pos;
336 12 size_and_pos warpret_pos[4];
337 12 size_and_pos enemy_prev_pos;
338
339 12 size_and_pos txtoffs_single;
340 12 size_and_pos txtoffs_double_1;
341 12 size_and_pos txtoffs_double_2;
342 int32_t panel_align = 1;
343
344 int32_t command_buttonwidth = 88;
345 int32_t command_buttonheight = 19;
346
347 int32_t layerpanel_buttonwidth = 58;
348 int32_t layerpanel_buttonheight = 16;
349
350 int32_t layerpanel_checkbox_hei = 13;
351 int32_t layerpanel_checkbox_wid = 13;
352
353 int32_t favorite_combos[MAXFAVORITECOMBOS];
354 byte favorite_combo_modes[MAXFAVORITECOMBOS];
355 bool ShowFavoriteComboModes;
356 byte FavoriteComboPage;
357
358 char comboprev_buf[512] = {0};
359 char comboprev_buf2[512] = {0};
360 FONT* txfont;
361
362 int32_t mouse_scroll_h;
363
364 // 'mapscreen' refers to the area of the editor where the screen is drawn.
365 int32_t mapscreen_x, mapscreen_y, showedges, showallpanels;
366 // The scale of the entire mapscreen area. This varies based on compact/extended mode.
367 static int mapscreen_screenunit_scale;
368 // The scale of an individual screen being drawn. This is `mapscreen_screenunit_scale / Map.getViewSize()`.
369 static double mapscreen_single_scale;
370 // 4 is roughly the largest value where things render okay. Beyond that, our low bitmap resolution results in tons
371 // of downsampling. Let users go to 16 anyway.
372 static int mapscreen_num_screens_to_draw_max = 16;
373 // The valid layers for the current screen(s).
374 static bool mapscreen_valid_layers[6];
375
376 struct VisibleScreen
377 {
378 int dx, dy;
379 int xoff, yoff;
380 mapscr* scr;
381 int screen;
382 };
383 static std::vector<VisibleScreen> visible_screens;
384 static VisibleScreen* active_visible_screen = nullptr;
385
386 static void set_active_visible_screen(mapscr* scr)
387 {
388 active_visible_screen = nullptr;
389 for (auto& visible_screen : visible_screens)
390 {
391 if (visible_screen.scr == scr)
392 {
393 active_visible_screen = &visible_screen;
394 break;
395 }
396 }
397 }
398
399 static ComboPosition get_mapscreen_mouse_combo_pos()
400 {
401 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
402 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
403 int cx = (gui_mouse_x()-startxint)/(16*mapscreen_single_scale);
404 int cy = (gui_mouse_y()-startyint)/(16*mapscreen_single_scale);
405 return ComboPosition{cx, cy};
406 }
407
408 static void refresh_visible_screens()
409 {
410 int num_screens = Map.getViewSize();
411 int screen_width = mapscreenbmp->w * mapscreen_single_scale;
412 int screen_height = mapscreenbmp->h * mapscreen_single_scale;
413
414 visible_screens.clear();
415 for (int dx = 0; dx < num_screens; dx++)
416 {
417 for (int dy = 0; dy < num_screens; dy++)
418 {
419 int mx = Map.getViewScr()%16 + dx;
420 int my = Map.getViewScr()/16 + dy;
421 if (mx < 0 || mx >= 16 || my < 0 || my >= 9)
422 continue;
423
424 int screen = Map.getViewScr() + dx + dy * 16;
425 if (screen >= MAPSCRS)
426 continue;
427
428 mapscr* scr = Map.Scr(screen);
429 int offx = dx * screen_width;
430 int offy = dy * screen_height;
431 visible_screens.emplace_back(VisibleScreen{dx, dy, offx, offy, scr, screen});
432 }
433 }
434
435 for (int i = 0; i < 6; i++)
436 {
437 mapscreen_valid_layers[i] = false;
438 for (auto& vis_screen : visible_screens)
439 {
440 mapscreen_valid_layers[i] |= vis_screen.scr->layermap[i] > 0;
441 }
442 }
443 }
444
445 int32_t readsize, writesize;
446 bool fake_pack_writing=false;
447
448 int32_t showxypos_x;
449 int32_t showxypos_y;
450 int32_t showxypos_w;
451 int32_t showxypos_h;
452 int32_t showxypos_color;
453 int32_t showxypos_ffc=-1000;
454 bool showxypos_icon=false;
455
456 int32_t showxypos_cursor_x;
457 int32_t showxypos_cursor_y;
458 bool showxypos_cursor_icon=false;
459 int32_t showxypos_cursor_color;
460 bool showxypos_dummy = false;
461
462 bool canfill=true; //to prevent double-filling (which stops undos)
463 int32_t lens_hint_item[MAXITEMS][2]; //aclk, aframe
464 int32_t lens_hint_weapon[MAXWPNS][5]; //aclk, aframe, dir, x, y
465 //int32_t mode, switch_mode, orig_mode;
466 int32_t tempmode=GFX_AUTODETECT;
467 RGB_MAP* zq_rgb_table;
468 MIDI *song=NULL;
469 BITMAP *mapscreenbmp, *screen2, *mouse_bmp[MOUSE_BMP_MAX][4], *mouse_bmp_1x[MOUSE_BMP_MAX][4], *icon_bmp[ICON_BMP_MAX][4], *flag_bmp[16][4], *select_bmp[2], *dmapbmp_small, *dmapbmp_large;
470 BITMAP *arrow_bmp[MAXARROWS],*brushbmp, *brushscreen; //*brushshadowbmp;
471 byte *colordata=NULL, *trashbuf=NULL;
472 itemdata *itemsbuf;
473 wpndata *wpnsbuf;
474 comboclass *combo_class_buf;
475 guydata *guysbuf;
476 item_drop_object item_drop_sets[MAXITEMDROPSETS];
477 midi_info Midi_Info;
478 bool zq_showpal=false;
479 bool is_compact = false;
480
481 int pixeldb = 1;
482 int infobg = 1;
483 bool large_merged_combopane = false;
484 bool compact_merged_combopane = true;
485 bool large_zoomed_fav = false;
486 bool compact_zoomed_fav = true;
487 bool large_zoomed_cmd = false;
488 bool compact_zoomed_cmd = true;
489
490 bool compact_square_panels = false;
491 int compact_active_panel = 0;
492
493 int combo_col_scale = 1;
494
495 std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
496 script_data *ffscripts[NUMSCRIPTFFC];
497 script_data *itemscripts[NUMSCRIPTITEM];
498 script_data *guyscripts[NUMSCRIPTGUYS];
499 script_data *lwpnscripts[NUMSCRIPTWEAPONS];
500 script_data *ewpnscripts[NUMSCRIPTWEAPONS];
501 script_data *globalscripts[NUMSCRIPTGLOBAL];
502 script_data *genericscripts[NUMSCRIPTSGENERIC];
503 script_data *playerscripts[NUMSCRIPTHERO];
504 script_data *screenscripts[NUMSCRIPTSCREEN];
505 script_data *dmapscripts[NUMSCRIPTSDMAP];
506 script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
507 script_data *comboscripts[NUMSCRIPTSCOMBODATA];
508 script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
509
510 extern string zScript;
511 char zScriptBytes[512];
512 char zLastVer[512] = { 0 };
513 SAMPLE customsfxdata[WAV_COUNT];
514 uint8_t customsfxflag[WAV_COUNT>>3];
515 int32_t sfxdat=1;
516
517 int32_t onImport_ComboAlias();
518 int32_t onExport_ComboAlias();
519
520 void set_console_state();
521
522 void clearConsole()
523 {
524 if(!console_is_open) return;
525 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
526 zscript_coloured_console.gotoxy(0,0);
527 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
528 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
529 }
530
531 void initConsole()
532 {
533 if(console_is_open) return;
534 console_is_open = 1;
535 set_console_state();
536 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
537 clearConsole();
538 }
539
540 11 void killConsole()
541 {
542
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(!console_is_open) return;
543 console_is_open = 0;
544 set_console_state();
545 zscript_coloured_console.kill();
546 11 }
547
548 int toggleConsole()
549 {
550 console_is_open ? killConsole() : initConsole();
551 zc_set_config("zquest","open_debug_console",console_is_open?1:0);
552 return D_O_K;
553 }
554
555 int showHotkeys()
556 {
557 hotkeys_run();
558 return D_O_K;
559 }
560
561 extern map_and_screen map_page[MAX_MAPPAGE_BTNS];
562
563 int32_t do_OpenQuest()
564 {
565 return onOpen();
566 }
567
568 int32_t do_NewQuest()
569 {
570 //clear the panel recent screen buttons to prevent crashes from invalid maps
571 for ( int32_t q = 0; q < 9; q++ )
572 {
573 map_page[q].map = 0;
574 map_page[q].screen = 0;
575 }
576 Map.setCurrMap(0);
577 Map.setCurrScr(0);
578 return onNew();
579 }
580
581 extern int CheckerCol1, CheckerCol2;
582 int32_t alignment_arrow_timer=0;
583 int32_t Flip=0,Combo=0,CSet=2,current_combolist=0,current_comboalist=0,current_cpoollist=0,current_cautolist=0,current_mappage=0;
584 int32_t Flags=0,Flag=0,menutype=(m_block);
585 int MouseScroll = 0, SavePaths = 0, CycleOn = 0, ShowGrid = 0, ShowScreenGrid = 0, ShowRegionGrid = 0, GridColor = 15, ShowCurScreenOutline = 1,
586 CmbCursorCol = 15, TilePgCursorCol = 15, CmbPgCursorCol = 15, TTipHLCol = 13,
587 TileProtection = 0, ComboProtection = 0, NoScreenPreview = 0, MMapCursorStyle = 0,
588 LayerDitherBG = -1, LayerDitherSz = 2, RulesetDialog = 0,
589 EnableTooltips = 0, TooltipsHighlight = 0, ShowFFScripts = 0, ShowSquares = 0,
590 ShowFFCs = 0, ShowInfo = 0, skipLayerWarning = 0,
591 DisableLPalShortcuts = 1, DisableCompileConsole = 0, numericalFlags = 0,
592 ActiveLayerHighlight = 0, DragCenterOfSquares = 0, SmartFFCPlacement = 0;
593 uint8_t InvalidBG = 0;
594 bool NoHighlightLayer0 = false;
595 // If true, uses "MapViewRTI" to draw editor screens. This allows for multiples palettes on the
596 // screen at once, and for higher resolution.
597 // Note: this is the default currently, and eventually the option should be removed and the
598 // "low-quality" rendering removed. Hasn't been done just yet just in case this causes regressions.
599 bool HighQualityScreenRendering = true;
600 int32_t FlashWarpSquare = -1, FlashWarpClk = 0; // flash the destination warp return when ShowSquares is active
601 uint8_t ViewLayer3BG = 0, ViewLayer2BG = 0;
602 int32_t window_width, window_height;
603 bool ShowFPS = false, SaveDragResize = false, DragAspect = false, SaveWinPos=false;
604 bool allowHideMouse = false;
605 double aspect_ratio = LARGE_H / double(LARGE_W);
606 int window_min_width = 0, window_min_height = 0;
607 int32_t ComboBrush = 0; //show the brush instead of the normal mouse
608 int32_t ComboBrushPause = 0; //temporarily disable the combo brush
609 int32_t FloatBrush = 0; //makes the combo brush float a few pixels up and left
610 int AutoBrush = 0; //Drag to size the brush on the combo panes
611 bool AutoBrushRevert = false; //Revert after placing
612 int LinkedScroll = 0;
613 //complete with shadow
614 int32_t OpenLastQuest = 0; //makes the program reopen the quest that was
615 //open at the time you quit
616 int32_t ShowMisalignments = 0; //makes the program display arrows over combos that are
617 //not aligned with the next screen.
618 int32_t AnimationOn = 0; //animate the combos in zquest?
619 int32_t AutoBackupRetention = 0; //use auto-backup feature? if so, how many backups (1-10) to keep
620 int32_t AutoSaveInterval = 0; //how often a timed autosave is made (not overwriting the current file)
621 int32_t UncompressedAutoSaves = 0; //should timed saves be uncompressed/encrypted?
622 int32_t KeyboardRepeatDelay = 0; //the time in milliseconds after holding down a key that the key starts to repeat
623 int32_t KeyboardRepeatRate = 0; //the time in milliseconds between each repetition of a repeated key
624
625 time_t auto_save_time_start, auto_save_time_current;
626 double auto_save_time_diff = 0;
627 int32_t AutoSaveRetention = 0; //how many autosaves of a quest to keep
628 int32_t ImportMapBias = 0; //tells what has precedence on map importing
629 int32_t BrushWidth=1, BrushHeight=1;
630 bool saved = true, autosaved = true;
631 bool __debug=false;
632 int32_t LayerMaskInt[7]={0};
633 int32_t CurrentLayer=0;
634 int32_t DuplicateAction[4]={0};
635 int32_t OnlyCheckNewTilesForDuplicates = 0;
636 int32_t try_recovering_missing_scripts = 0;
637
638 uint8_t PreFillTileEditorPage = 0, PreFillComboEditorPage = 0;
639 int32_t DMapEditorLastMaptileUsed = 0;
640
641 /*
642 , HorizontalDuplicateAction;
643 int32_t VerticalDuplicateAction, BothDuplicateAction;
644 */
645 word msg_count = 0;
646 int32_t LeechUpdate = 0;
647 int32_t LeechUpdateTiles = 0;
648 int32_t SnapshotFormat = 0;
649 byte SnapshotScale = 0;
650
651 byte Color = 0;
652 extern int32_t jwin_pal[jcMAX];
653 int32_t gui_colorset=99;
654
655 static int32_t combo_apos=0; //currently selected combo alias
656 int32_t alias_origin=0;
657 int32_t alias_cset_mod=0;
658
659 static int32_t combo_pool_pos=0; //currently selected combo pool
660 bool weighted_cpool = true;
661 bool cpool_prev_visible = false;
662
663 static int32_t combo_auto_pos=0; //currently selected autocombo
664 byte cauto_height = 1;
665
666 bool trip=false;
667
668 int32_t fill_type=1;
669
670 bool first_save=false;
671 char *filepath,*midipath,*datapath,*imagepath,*tmusicpath,*last_timed_save;
672 string helpstr, zstringshelpstr;
673
674 ZCMUSIC *zcmusic = NULL;
675 ZCMIXER *zcmixer = NULL;
676 int32_t midi_volume = 255;
677 extern int32_t prv_mode;
678 int32_t prv_warp = 0;
679 int32_t prv_twon = 0;
680
681 int32_t Frameskip = 0, RequestedFPS = 60, zqUseWin32Proc = 1;
682 int32_t zqColorDepth = 8;
683
684 11 void set_last_timed_save(char const* buf)
685 {
686
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if(buf && buf[0])
687 {
688 if(buf != last_timed_save)
689 strcpy(last_timed_save, buf);
690 }
691 else
692 {
693 11 last_timed_save[0] = 0;
694 11 buf = nullptr;
695 }
696 11 zc_set_config("zquest","last_timed_save",buf);
697 11 }
698
699 17 void mark_save_dirty()
700 {
701 17 saved = false;
702 17 autosaved = false;
703 17 }
704
705 void loadlvlpal(int32_t level);
706 bool get_debug()
707 {
708 return __debug;
709 //return true;
710 }
711
712 void set_debug(bool d)
713 {
714 __debug=d;
715 return;
716 }
717
718 bool handle_quit()
719 {
720 if(onExit()==D_CLOSE)
721 return (exiting_program = true);
722 return false;
723 }
724 bool handle_close_btn_quit()
725 {
726 if(close_button_quit)
727 {
728 close_button_quit=false;
729 return handle_quit();
730 }
731 return false;
732 }
733 // **** Timers ****
734
735 volatile int32_t lastfps=0;
736 volatile int32_t framecnt=0;
737 size_t cpoolbrush_index = 0;
738
739 // quest data
740 12 zquestheader header;
741 byte midi_flags[MIDIFLAGS_SIZE];
742 byte music_flags[MUSICFLAGS_SIZE];
743 byte *quest_file;
744 int32_t msg_strings_size;
745 zctune *customtunes;
746 //emusic *enhancedMusic;
747 ZCHEATS zcheats;
748 byte use_cheats;
749 byte use_tiles;
750 // Note: may not be null-terminated (must refactor writecolordata to fix).
751 char palnames[MAXLEVELS][17];
752 char zquestdat_sig[52];
753 char qstdat_str[2048];
754
755 int32_t gme_track=0;
756
757 int32_t dlevel; // just here until gamedata is properly done
758
759 12 bool bad_version(int32_t ver)
760 {
761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(ver < 0x170)
762 return true;
763
764 12 return false;
765 12 }
766
767 // These are for drawing eyeballs correctly in combo_tile.
768 zfix HeroModifiedX()
769 {
770 return gui_mouse_x() - 7;
771 }
772 zfix HeroModifiedY()
773 {
774 return gui_mouse_y() - 7;
775 }
776
777
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_250_menu
778 48 {
779
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onImport_DMaps },
780
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Table", onImport_Combos },
781
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onImport_ComboAlias },
782 };
783
784
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_graphics
785 180 {
786
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onImport_Pals },
787
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
788
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Tileset (&Full)", onImport_Tiles },
789
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Pack", onImport_Tilepack },
790
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "T&ile Pack to...", onImport_Tilepack_To },
791
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
792
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Set (Range)", onImport_Combos },
793
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack (Full, 1:1)", onImport_Combopack },
794
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack to... (Dest)", onImport_Combopack_To },
795
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
796
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Alias Pack", onImport_Comboaliaspack },
797
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo A&lias Pack to...", onImport_Comboaliaspack_To },
798
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
799
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doorsets", onImport_Doorset },
800 };
801
802
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_menu
803 120 {
804
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onImport_Guys },
805
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map", onImport_Map },
806
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onImport_DMaps },
807
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings (.tsv)", onImport_StringsTSV },
808
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "String Table (deprecated)", onImport_Msgs },
809
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
810
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics", &import_graphics },
811
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
812
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2.50 (Broken)", &import_250_menu },
813 };
814
815
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_250_menu
816 60 {
817
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onExport_DMaps },
818
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Table", onExport_Combos },
819
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onExport_ComboAlias },
820
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics Pack", onExport_ZGP },
821 };
822
823
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu zq_help_menu
824 36 {
825
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Editor Help", onHelp },
826
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings Help", onZstringshelp },
827 };
828
829
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_graphics
830 144 {
831
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onExport_Pals },
832
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
833
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Tileset (&Full)", onExport_Tiles },
834
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Pack", onExport_Tilepack },
835
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
836
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Set", onExport_Combos },
837
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack", onExport_Combopack },
838
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
839
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Alias Pack", onExport_Comboaliaspack },
840
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
841
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doorsets", onExport_Doorset },
842 };
843
844
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_menu
845 132 {
846 #ifdef _WIN32
847 { "&Package", onExport_Package },
848 #endif
849
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onExport_Guys },
850
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map", onExport_Map },
851
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onExport_DMaps },
852
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
853
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings (.tsv)", onExport_StringsTSV },
854
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "String Table (deprecated)", onExport_Msgs },
855
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
856
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics", &export_graphics },
857
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
858
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2.50 (Broken)", &export_250_menu },
859 };
860
861
862
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu recent_menu
863 132 {
864
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
865
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
866
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
867
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
868
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
869
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
870
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
871
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
872
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
873
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
874 };
875 static char rec_menu_fullpaths[10][512];
876 static char rec_menu_strs[10][64];
877
878 int32_t customOpen(char const* path);
879 void do_recent_quest(uint32_t ind)
880 {
881 if(ind > 9) return;
882 strcpy(temppath, rec_menu_fullpaths[ind]);
883 customOpen(temppath);
884 }
885 int32_t do_RecentQuest_0() { do_recent_quest(0); return D_O_K; }
886 int32_t do_RecentQuest_1() { do_recent_quest(1); return D_O_K; }
887 int32_t do_RecentQuest_2() { do_recent_quest(2); return D_O_K; }
888 int32_t do_RecentQuest_3() { do_recent_quest(3); return D_O_K; }
889 int32_t do_RecentQuest_4() { do_recent_quest(4); return D_O_K; }
890 int32_t do_RecentQuest_5() { do_recent_quest(5); return D_O_K; }
891 int32_t do_RecentQuest_6() { do_recent_quest(6); return D_O_K; }
892 int32_t do_RecentQuest_7() { do_recent_quest(7); return D_O_K; }
893 int32_t do_RecentQuest_8() { do_recent_quest(8); return D_O_K; }
894 int32_t do_RecentQuest_9() { do_recent_quest(9); return D_O_K; }
895
896 2 void refresh_recent_menu()
897 {
898 2 int32_t (*procs[10])(void) = {
899 do_RecentQuest_0, do_RecentQuest_1, do_RecentQuest_2, do_RecentQuest_3,
900 do_RecentQuest_4, do_RecentQuest_5, do_RecentQuest_6,
901 do_RecentQuest_7, do_RecentQuest_8, do_RecentQuest_9
902 };
903
5/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
2 static MenuItem nilitem("---",nullptr,nullopt,true);
904
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
22 for(auto q = 0; q < 10; ++q)
905 {
906 20 MenuItem& mit = *recent_menu.at(q);
907 20 bool valid = rec_menu_fullpaths[q][0] != '-';
908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(valid)
909 mit = MenuItem(rec_menu_strs[q],procs[q]);
910 20 else mit = nilitem;
911 20 }
912 2 }
913
914 1 void load_recent_quests()
915 {
916 1 char configname[64] = "rec_qst_";
917 1 char* ptr = &configname[strlen(configname)];
918 1 char buf[512] = {0};
919
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for(auto q = 0; q < 10; ++q)
920 {
921 10 sprintf(ptr, "%d", q); //increment the configname value
922 10 char const* qst_str = zc_get_config("recent",configname,nullptr);
923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(qst_str[0])
924 {
925 strncpy(rec_menu_fullpaths[q], qst_str, 511);
926 relativize_path(buf, rec_menu_fullpaths[q]);
927 if(strlen(buf) > 62)
928 {
929 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
930 }
931 strncpy(rec_menu_strs[q], buf, 63);
932 }
933 else
934 {
935 10 strcpy(rec_menu_fullpaths[q], "---");
936 10 strcpy(rec_menu_strs[q], "---");
937 }
938 10 rec_menu_fullpaths[q][511] = 0;
939 10 rec_menu_strs[q][63] = 0;
940 10 }
941 1 refresh_recent_menu();
942 1 }
943
944 void write_recent_quests()
945 {
946 char configname[64] = "rec_qst_";
947 char* ptr = &configname[strlen(configname)];
948 for(auto q = 0; q < 10; ++q)
949 {
950 sprintf(ptr, "%d", q); //increment the configname value
951 zc_set_config("recent",configname,(rec_menu_fullpaths[q][0]!='-') ? rec_menu_fullpaths[q] : nullptr);
952 }
953 }
954
955 void update_recent_quest(char const* path)
956 {
957 int32_t ind = -1;
958 for(auto q = 0; q < 10; ++q)
959 {
960 if(!strcmp(path, rec_menu_fullpaths[q]))
961 {
962 ind = q;
963 break;
964 }
965 }
966 if(ind > -1)
967 {
968 for(auto q = ind; q > 0; --q)
969 {
970 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
971 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
972 }
973 }
974 else
975 {
976 int32_t free_ind = 9; //if none found, override the last index
977 for(auto q = 0; q < 9; ++q)
978 {
979 if(rec_menu_fullpaths[q][0] == '-')
980 {
981 free_ind = q;
982 break;
983 }
984 }
985
986 for(auto q = free_ind; q > 0; --q)
987 {
988 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
989 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
990 }
991 }
992 char buf[512] = {0};
993 strcpy(rec_menu_fullpaths[0], path);
994 relativize_path(buf, rec_menu_fullpaths[0]);
995 if(strlen(buf) > 62)
996 {
997 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
998 }
999 strncpy(rec_menu_strs[0], buf, 63);
1000 refresh_recent_menu();
1001 zc_set_config("zquest",last_quest_name,path);
1002 write_recent_quests();
1003 }
1004
1005 void reload_zq_gui()
1006 {
1007 init_custom_fonts();
1008 load_size_poses();
1009 refresh_visible_screens();
1010 update_combobrush();
1011 refresh(rCLEAR|rALL);
1012 }
1013 void change_mapscr_zoom(int delta)
1014 {
1015 int num_screens = Map.getViewSize();
1016 num_screens = std::clamp(num_screens + delta, 1, mapscreen_num_screens_to_draw_max);
1017 Map.setViewSize(num_screens);
1018 std::string qst_cfg_header = qst_cfg_header_from_path(filepath);
1019 zc_set_config(qst_cfg_header.c_str(), "zoom_num_screens", Map.getViewSize());
1020 reload_zq_gui();
1021 }
1022 void toggle_is_compact()
1023 {
1024 is_compact = !is_compact;
1025 zc_set_config("ZQ_GUI","compact_mode",is_compact?1:0);
1026 reload_zq_gui();
1027 }
1028 void toggle_merged_mode()
1029 {
1030 if(is_compact)
1031 {
1032 compact_merged_combopane = !compact_merged_combopane;
1033 zc_set_config("ZQ_GUI","merge_cpane_compact",compact_merged_combopane?1:0);
1034 }
1035 else
1036 {
1037 large_merged_combopane = !large_merged_combopane;
1038 zc_set_config("ZQ_GUI","merge_cpane_large",large_merged_combopane?1:0);
1039 }
1040 reload_zq_gui();
1041 }
1042 void toggle_compact_sqr_mode()
1043 {
1044 compact_square_panels = !compact_square_panels;
1045 zc_set_config("ZQ_GUI","square_panels_compact",compact_square_panels?1:0);
1046 reload_zq_gui();
1047 }
1048 void cycle_compact_sqr(bool down)
1049 {
1050 if(!(is_compact && compact_square_panels))
1051 return;
1052 static const int num_panels = 3;
1053 if(down)
1054 compact_active_panel = (compact_active_panel+1)%num_panels;
1055 else
1056 compact_active_panel = (compact_active_panel-1+num_panels)%num_panels;
1057 reload_zq_gui();
1058 }
1059 void toggle_favzoom_mode()
1060 {
1061 if(is_compact)
1062 {
1063 compact_zoomed_fav = !compact_zoomed_fav;
1064 zc_set_config("ZQ_GUI","zoom_fav_compact",compact_zoomed_fav?1:0);
1065 }
1066 else
1067 {
1068 large_zoomed_fav = !large_zoomed_fav;
1069 zc_set_config("ZQ_GUI","zoom_fav_large",large_zoomed_fav?1:0);
1070 }
1071 reload_zq_gui();
1072 }
1073 void toggle_cmdzoom_mode()
1074 {
1075 if(is_compact)
1076 {
1077 compact_zoomed_cmd = !compact_zoomed_cmd;
1078 zc_set_config("ZQ_GUI","zoom_cmd_compact",compact_zoomed_cmd?1:0);
1079 }
1080 else
1081 {
1082 large_zoomed_cmd = !large_zoomed_cmd;
1083 zc_set_config("ZQ_GUI","zoom_cmd_large",large_zoomed_cmd?1:0);
1084 }
1085 reload_zq_gui();
1086 }
1087
1088 enum
1089 {
1090 MENUID_FILE_SAVE,
1091 MENUID_FILE_SAVEAS,
1092 MENUID_FILE_REVERT,
1093 };
1094
1095
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu file_menu
1096 156 {
1097
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&New", do_NewQuest },
1098
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Open", do_OpenQuest },
1099
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Recent", &recent_menu },
1100
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1101
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Save", onSave, MENUID_FILE_SAVE },
1102
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Save &as...", onSaveAs, MENUID_FILE_SAVEAS },
1103
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Revert", onRevert, MENUID_FILE_REVERT },
1104
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1105
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Import", &import_menu },
1106
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Export", &export_menu },
1107 #ifndef __EMSCRIPTEN__
1108
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1109
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "E&xit", handle_quit },
1110 #endif
1111 };
1112
1113 enum
1114 {
1115 MENUID_MAPS_NEXT,
1116 MENUID_MAPS_PREV,
1117 };
1118
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu maps_menu
1119 72 {
1120
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Goto Map...", onGotoMap },
1121
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Next Map", onIncMap, MENUID_MAPS_NEXT },
1122
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Previous Map", onDecMap, MENUID_MAPS_PREV },
1123
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1124
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "D&elete Map", onDeleteMap },
1125 };
1126
1127
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu misc_menu
1128 132 {
1129
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "S&ubscreens", onEditSubscreens },
1130
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Shop Types", onShopTypes },
1131
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Bottle Types", onBottleTypes },
1132
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Bottle S&hop Types", onBottleShopTypes },
1133
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Info Types", onInfoTypes },
1134
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warp Rings", onWarpRings },
1135
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Triforce Pieces", onTriPieces },
1136
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&End String", onEndString },
1137
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Item &Drop Sets", onItemDropSets },
1138
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Save Menus", onSaveMenus },
1139 };
1140
1141
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu spr_menu
1142 48 {
1143
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprite Data", onCustomWpns },
1144
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hero", onCustomHero },
1145
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Misc Sprites", onMiscSprites },
1146 };
1147
1148
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 NewMenu colors_menu
1149 48 {
1150
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Main ", onColors_Main },
1151
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Levels ", onColors_Levels },
1152
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprites ", onColors_Sprites },
1153 };
1154
1155
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu defs_menu
1156 108 {
1157
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onDefault_Pals },
1158
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tiles", onDefault_Tiles },
1159
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combos", onDefault_Combos },
1160
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Items", onDefault_Items },
1161
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onDefault_Guys },
1162
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprite Data", onDefault_Weapons },
1163
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map Styles", onDefault_MapStyles },
1164
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "SF&X Data", onDefault_SFX },
1165 };
1166
1167 int32_t onEditComboAlias();
1168 int32_t onEditComboPool();
1169 int32_t onEditAutoCombo();
1170
1171
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu graphics_menu
1172 144 {
1173
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes ", &colors_menu },
1174
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprites ", &spr_menu },
1175
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combos", onCombos },
1176
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tiles", onTiles },
1177
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Game icons", onIcons },
1178
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Misc co&lors", onMiscColors },
1179
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map styles", onMapStyles },
1180
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Door Combo Sets", onDoorCombos },
1181
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Aliases", [](){call_alias_pages(); return D_O_K;} },
1182
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pools", [](){call_cpool_pages(); return D_O_K;} },
1183
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Auto Combos", [](){call_autoc_pages(); return D_O_K;} },
1184 };
1185
1186
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu audio_menu
1187 48 {
1188
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "SF&X Data", onSelectSFX },
1189
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&MIDIs", onMidis },
1190
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Mis&c SFX", onMiscSFX },
1191 };
1192
1193 void set_rules(byte* newrules);
1194
1195 void call_testqst_dialog();
1196 int32_t onTestQst()
1197 {
1198 call_testqst_dialog();
1199 return D_O_K;
1200 }
1201
1202 int32_t onRulesDlg()
1203 {
1204 call_qr_dialog(21, set_rules);
1205 return D_O_K;
1206 }
1207
1208 int32_t onRulesSearch()
1209 {
1210 call_qrsearch_dialog(set_rules);
1211 return D_O_K;
1212 }
1213
1214 int32_t onZScriptSettings()
1215 {
1216 ScriptRulesDialog(quest_rules, 17, [](byte* newrules)
1217 {
1218 mark_save_dirty();
1219 memcpy(quest_rules, newrules, QR_SZ);
1220 unpack_qrs();
1221 }).show();
1222 return D_O_K;
1223 }
1224
1225 void call_zinf_dlg();
1226 int32_t onZInfo()
1227 {
1228 call_zinf_dlg();
1229 return D_O_K;
1230 }
1231
1232
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu quest_menu
1233 204 {
1234
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Options ", onRulesDlg },
1235
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Test", onTestQst },
1236
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Items", onCustomItems },
1237
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onCustomEnemies },
1238
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hero", onCustomHero },
1239
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings", onStrings },
1240
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onDmaps },
1241
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map Settings", onMaps },
1242
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "I&nit Data", onInit },
1243
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Misc D&ata ", &misc_menu },
1244
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&ZInfo", onZInfo },
1245
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1246
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics ", &graphics_menu },
1247
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "A&udio ", &audio_menu },
1248
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1249
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "De&faults ", &defs_menu },
1250 };
1251
1252
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_menu
1253 36 {
1254
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &To All", onPasteToAll },
1255
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &All To All", onPasteAllToAll },
1256 };
1257
1258
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_item_menu
1259 156 {
1260
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Undercombo", onPasteUnderCombo },
1261
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Secret Combos", onPasteSecretCombos },
1262
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Freeform Combos", onPasteFFCombos },
1263
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Screen &Data", onPasteScreenData },
1264
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warps", onPasteWarps },
1265
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Warp &Return", onPasteWarpLocations },
1266
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onPasteEnemies },
1267
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Room &Type Data", onPasteRoom },
1268
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Guy/String", onPasteGuy },
1269
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Doo&rs", onPasteDoors },
1270
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Layers", onPasteLayers },
1271
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palette", onPastePalette },
1272 };
1273
1274 enum
1275 {
1276 MENUID_EDIT_UNDO,
1277 MENUID_EDIT_REDO,
1278 MENUID_EDIT_COPY,
1279 MENUID_EDIT_PASTE,
1280 MENUID_EDIT_PASTEALL,
1281 MENUID_EDIT_ADVPASTE,
1282 MENUID_EDIT_SPECPASTE,
1283 MENUID_EDIT_DELETE,
1284 };
1285
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu edit_menu
1286 132 {
1287
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Undo", onUndo, MENUID_EDIT_UNDO },
1288
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Redo", onRedo, MENUID_EDIT_REDO },
1289
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Copy", onCopy, MENUID_EDIT_COPY },
1290
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Paste", onPaste, MENUID_EDIT_PASTE },
1291
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste A&ll", onPasteAll, MENUID_EDIT_PASTEALL },
1292
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Adv. Paste ", &paste_menu, MENUID_EDIT_ADVPASTE },
1293
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &Spec. ", &paste_item_menu, MENUID_EDIT_SPECPASTE },
1294
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Delete", onDelete, MENUID_EDIT_DELETE },
1295
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1296
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Maps ", &maps_menu },
1297 };
1298
1299
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu drawing_mode_menu
1300 60 {
1301
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Normal", onDrawingModeNormal, dm_normal },
1302
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onDrawingModeAlias, dm_alias },
1303
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Pool", onDrawingModePool, dm_cpool },
1304
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Auto Combo", onDrawingModeAuto, dm_auto },
1305 };
1306
1307
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu integrity_check_menu
1308 48 {
1309
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&All ", onIntegrityCheckAll },
1310
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screens ", onIntegrityCheckRooms },
1311
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warps ", onIntegrityCheckWarps },
1312 };
1313
1314
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu quest_reports_menu
1315 108 {
1316
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Bugged Next-> Combo Locations", onBuggedNextComboLocationReport },
1317
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Locations", onComboLocationReport },
1318
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Type Locations", onComboTypeLocationReport },
1319
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemy Locations", onEnemyLocationReport },
1320
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Item Locations", onItemLocationReport },
1321
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Script Locations", onScriptLocationReport },
1322
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&What Links Here", onWhatWarpsReport },
1323
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "In&tegrity Check ", &integrity_check_menu },
1324 };
1325
1326 int32_t onPalFix();
1327 int32_t onPitFix();
1328 int32_t onStrFix()
1329 {
1330 if(get_qr(qr_OLD_STRING_EDITOR_MARGINS))
1331 {
1332 if (alert_confirm("Fix: Old Margins",
1333 "Fixing margins may cause strings that used to spill outside the textbox"
1334 " to instead be cut off. Are you sure?"))
1335 {
1336 set_qr(qr_OLD_STRING_EDITOR_MARGINS, 0);
1337 mark_save_dirty();
1338 }
1339 }
1340 if(get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT))
1341 {
1342 if (alert_confirm("Fix: Old Frame Size",
1343 "This will fix the frame size of all strings. No visual changes should occur,"
1344 " as the string width/height will be fixed, but the compat QR will also be unchecked."))
1345 {
1346 for(auto q = 0; q < msg_count; ++q)
1347 {
1348 MsgStrings[q].w += 16;
1349 MsgStrings[q].h += 16;
1350 }
1351 set_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT, 0);
1352 mark_save_dirty();
1353 }
1354 }
1355 return D_O_K;
1356 }
1357
1358 int32_t onRemoveOldArrivalSquare();
1359 enum
1360 {
1361 MENUID_FIXTOOL_OLDSTRING,
1362 };
1363
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu fixtools_menu
1364 96 {
1365
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Color Set Fix", onCSetFix },
1366
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Liquid Solidity Fix", onWaterSolidity },
1367
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Effect Square Fix", onEffectFix },
1368
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Level Palette Fix", onPalFix },
1369
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Pit and Liquid Damage Fix", onPitFix },
1370
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Old Strings Fix", onStrFix, MENUID_FIXTOOL_OLDSTRING },
1371
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Green Arrival Square Fix", onRemoveOldArrivalSquare },
1372 };
1373
1374
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu tool_menu
1375 132 {
1376
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Flags", onFlags, nullopt, MFL_EXIT_PRE_PROC },
1377
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fix &Tools ", &fixtools_menu },
1378
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&NES Dungeon Template", onTemplate },
1379
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Apply Template to All", onReTemplate },
1380
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1381
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Preview Mode", onPreviewMode },
1382
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Drawing &Mode ", &drawing_mode_menu },
1383
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1384
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&List Combos Used", onUsedCombos },
1385
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest Reports ", &quest_reports_menu },
1386 };
1387
1388 int32_t onLayer3BG()
1389 {
1390 ViewLayer3BG = ViewLayer3BG ? 0 : 1;
1391 zc_set_config("zquest","layer3_bg",ViewLayer3BG);
1392 return D_O_K;
1393 }
1394 int32_t onLayer2BG()
1395 {
1396 ViewLayer2BG = ViewLayer2BG ? 0 : 1;
1397 zc_set_config("zquest","layer2_bg",ViewLayer2BG);
1398 return D_O_K;
1399 }
1400 int onGridToggle();
1401 int onToggleHighQualityScreenRendering();
1402 enum
1403 {
1404 MENUID_VIEW_WALKABILITY,
1405 MENUID_VIEW_FLAGS,
1406 MENUID_VIEW_CSET,
1407 MENUID_VIEW_TYPES,
1408 MENUID_VIEW_INFO,
1409 MENUID_VIEW_SQUARES,
1410 MENUID_VIEW_FFCS,
1411 MENUID_VIEW_SCRIPTNAMES,
1412 MENUID_VIEW_GRID,
1413 MENUID_VIEW_SCREENGRID,
1414 MENUID_VIEW_REGIONGRID,
1415 MENUID_VIEW_CURSCROUTLINE,
1416 MENUID_VIEW_DARKNESS,
1417 MENUID_VIEW_L2BG,
1418 MENUID_VIEW_L3BG,
1419 MENUID_VIEW_LAYERHIGHLIGHT,
1420 MENUID_VIEW_HIGH_QUALITY_SCREEN_RENDERING,
1421 };
1422
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 NewMenu view_menu
1423 264 {
1424
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "View &Map...", onViewMap },
1425
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "View &Palette", onShowPal },
1426
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1427
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Walkability", onShowWalkability, MENUID_VIEW_WALKABILITY },
1428
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Flags", onShowFlags, MENUID_VIEW_FLAGS },
1429
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &CSets", onShowCSet, MENUID_VIEW_CSET },
1430
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Types", onShowCType, MENUID_VIEW_TYPES },
1431
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1432
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Screen &Info", onToggleShowInfo, MENUID_VIEW_INFO },
1433
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Squares", onToggleShowSquares, MENUID_VIEW_SQUARES },
1434
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show FFCs", onToggleShowFFCs, MENUID_VIEW_FFCS },
1435
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Script &Names", onToggleShowScripts, MENUID_VIEW_SCRIPTNAMES },
1436
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Grid", onGridToggle, MENUID_VIEW_GRID },
1437
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Screen G&rid", onToggleScreenGrid, MENUID_VIEW_SCREENGRID },
1438
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Region Grid", onToggleRegionGrid, MENUID_VIEW_REGIONGRID },
1439
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Current Screen Outline", onToggleCurrentScreenOutline, MENUID_VIEW_CURSCROUTLINE },
1440
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Darkness", onShowDarkness, MENUID_VIEW_DARKNESS },
1441
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Layer 2 is Background", onLayer2BG, MENUID_VIEW_L2BG },
1442
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Layer 3 is Background", onLayer3BG, MENUID_VIEW_L3BG },
1443
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Highlight Current Layer", onToggleHighlightLayer, MENUID_VIEW_LAYERHIGHLIGHT },
1444
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "High &Quality Screen Rendering", onToggleHighQualityScreenRendering, MENUID_VIEW_HIGH_QUALITY_SCREEN_RENDERING },
1445 };
1446
1447 11 void set_rules(byte* newrules)
1448 {
1449 11 mark_save_dirty();
1450
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(newrules != quest_rules)
1451 memcpy(quest_rules, newrules, QR_SZ);
1452 11 unpack_qrs();
1453
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 if(!get_qr(qr_ALLOW_EDITING_COMBO_0))
1454 {
1455 2 combobuf[0].walk = 0xF0;
1456 2 combobuf[0].type = 0;
1457 2 combobuf[0].flag = 0;
1458 2 }
1459
1460 // For 2.50.0 and 2.50.1
1461
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 if(get_qr(qr_VERYFASTSCROLLING))
1462 2 set_qr(qr_FASTDNGN, 1);
1463 11 }
1464
1465 int32_t onSelectFFCombo();
1466
1467 void onScreenNotes()
1468 {
1469 edit_screen_notes(Map.CurrScr(), Map.getCurrMap(), Map.getCurrScr());
1470 }
1471
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu data_menu
1472 216 {
1473
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screen Data", onScrData },
1474
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Freeform Combos", onSelectFFCombo },
1475
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "La&yers", onLayers },
1476
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Warp", onTileWarp },
1477
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Side &Warp", onSideWarp },
1478
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Secret &Combos", onSecretCombo },
1479
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Under Combo", onUnderCombo },
1480
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doors", onDoors },
1481
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Maze Path", onPath },
1482
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1483
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Item", onItem },
1484
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onEnemies },
1485
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palette", onScreenPalette },
1486
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1487
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Room Data", onRoom },
1488
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Notes", onScreenNotes },
1489
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Browse Notes", browse_screen_notes },
1490 };
1491
1492
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu tunes_menu
1493 252 {
1494
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "ZC Forever", playZCForever },
1495
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Wind Fish", playTune1 },
1496
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Overworld", playTune2 },
1497
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Hyrule Castle", playTune3 },
1498
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Lost Woods", playTune4 },
1499
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Great Sea", playTune5 },
1500
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "East Hyrule", playTune6 },
1501
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dancing Dragon", playTune7 },
1502
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Stone Tower", playTune8 },
1503
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Villages", playTune9 },
1504
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Swamp + Desert", playTune10 },
1505
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Outset Island", playTune11 },
1506
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Kakariko Village", playTune12 },
1507
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Clock Town", playTune13 },
1508
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Temple", playTune14 },
1509
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dark World", playTune15 },
1510
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dragon Roost", playTune16 },
1511
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Horse Race", playTune17 },
1512
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Credits", playTune18 },
1513
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Zelda's Lullaby", playTune19 },
1514 };
1515
1516 enum
1517 {
1518 MENUID_MEDIA_TUNES,
1519 MENUID_MEDIA_PLAYMUSIC,
1520 MENUID_MEDIA_CHANGETRACK,
1521 };
1522
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu media_menu
1523 60 {
1524
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Ambient Music ", &tunes_menu, MENUID_MEDIA_TUNES },
1525
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Play music", playMusic, MENUID_MEDIA_PLAYMUSIC },
1526
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Change track", changeTrack, MENUID_MEDIA_CHANGETRACK },
1527
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Stop tunes", stopMusic },
1528 };
1529
1530 enum
1531 {
1532 MENUID_ETC_VIDMODE,
1533 MENUID_ETC_FULLSCREEN,
1534 MENUID_ETC_DEBUG_CONSOLE,
1535 };
1536
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu etc_menu
1537 192 {
1538
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Help", &zq_help_menu },
1539
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&About", onAbout },
1540
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Video Mode", onZQVidMode, MENUID_ETC_VIDMODE },
1541
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Options...", onOptions },
1542
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hotkeys...", do_zq_hotkey_dialog },
1543
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&List Hotkeys...", do_zq_list_hotkeys_dialog },
1544
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Fullscreen", onFullScreen, MENUID_ETC_FULLSCREEN },
1545
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1546
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&View Pic...", onViewPic },
1547
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Media", &media_menu },
1548
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1549
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Debug Console", toggleConsole, MENUID_ETC_DEBUG_CONSOLE },
1550
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Clear Quest Filepath", onClearQuestFilepath },
1551
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Take ZQ Snapshot", onMenuSnapshot },
1552
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Take &Screen Snapshot", onMapscrSnapshot },
1553 };
1554
1555
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu zscript_menu
1556 60 {
1557
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Compile &ZScript...", onCompileScript },
1558
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1559
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Compiler Settings", onZScriptCompilerSettings },
1560
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest Script Settings", onZScriptSettings },
1561 };
1562
1563 void set_console_state()
1564 {
1565 etc_menu.select_uid(MENUID_ETC_DEBUG_CONSOLE, console_is_open);
1566 }
1567
1568
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 TopMenu the_menu
1569 108 {
1570
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&File", &file_menu },
1571
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest", &quest_menu },
1572
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Edit", &edit_menu },
1573
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&View", &view_menu },
1574
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tools", &tool_menu },
1575
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screen", &data_menu },
1576
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&ZScript", &zscript_menu },
1577
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Et&C", &etc_menu },
1578 };
1579
1580 void rebuild_trans_table();
1581 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal,
1582 int32_t &px2, int32_t &py2, double &scale, bool isviewingmap, bool skipmenu = false);
1583
1584 int32_t onResetTransparency()
1585 {
1586 restore_mouse();
1587 rebuild_trans_table();
1588 displayinfo("Notice","Translucency Table Rebuilt");
1589
1590 refresh(rALL);
1591 return D_O_K;
1592 }
1593
1594 int32_t onFullScreen()
1595 {
1596 get_palette(RAMpal);
1597 bool windowed=is_windowed_mode()!=0;
1598 all_toggle_fullscreen(windowed);
1599
1600 gui_mouse_focus=0;
1601 gui_bg_color=jwin_pal[jcBOX];
1602 gui_fg_color=jwin_pal[jcBOXFG];
1603 MouseSprite::set(ZQM_NORMAL);
1604 zc_set_palette(RAMpal);
1605 position_mouse(zq_screen_w/2,zq_screen_h/2);
1606 set_display_switch_mode(SWITCH_BACKGROUND);
1607 set_display_switch_callback(SWITCH_OUT, switch_out);
1608 set_display_switch_callback(SWITCH_IN, switch_in);
1609 zc_set_config("zquest","fullscreen", is_windowed_mode() ? 0 : 1);
1610 return D_REDRAW;
1611 }
1612
1613 int32_t onEnter()
1614 {
1615 if(key[KEY_ALT]||key[KEY_ALTGR])
1616 {
1617 return onFullScreen();
1618 }
1619
1620 return D_O_K;
1621 }
1622
1623 //PROC, x, y, w, h, fg, bg, key, flags, d1, d2, *dp, *dp2, *dp3
1624
1625 //*text, (*proc), *child, flags, *dp
1626
1627 void run_zq_frame();
1628 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c);
1629
1630
1631 /*int32_t onY()
1632 {
1633 return D_O_K;
1634 }*/
1635
1636 int32_t onToggleGrid(bool color)
1637 {
1638 if(color)
1639 {
1640 GridColor=(GridColor+8)%16;
1641 zc_set_config("zquest", "grid_color", GridColor);
1642 }
1643 else
1644 {
1645 ShowGrid=!ShowGrid;
1646 zc_set_config("zquest","show_grid",ShowGrid);
1647 }
1648
1649 return D_O_K;
1650 }
1651
1652 int onGridToggle()
1653 {
1654 return onToggleGrid(CHECK_CTRL_CMD);
1655 }
1656
1657 int onToggleHighQualityScreenRendering()
1658 {
1659 HighQualityScreenRendering = !HighQualityScreenRendering;
1660 zc_set_config("zquest","high_quality_screen_rendering",HighQualityScreenRendering);
1661
1662 if (!HighQualityScreenRendering)
1663 {
1664 mapview_get_rti()->remove();
1665 }
1666
1667 return D_O_K;
1668 }
1669
1670 int32_t onToggleScreenGrid()
1671 {
1672 ShowScreenGrid=!ShowScreenGrid;
1673 zc_set_config("zquest","show_screen_grid",ShowScreenGrid);
1674 return D_O_K;
1675 }
1676
1677 int32_t onToggleRegionGrid()
1678 {
1679 ShowRegionGrid=!ShowRegionGrid;
1680 zc_set_config("zquest","show_region_grid",ShowRegionGrid);
1681 return D_O_K;
1682 }
1683
1684 int32_t onToggleCurrentScreenOutline()
1685 {
1686 ShowCurScreenOutline=!ShowCurScreenOutline;
1687 zc_set_config("zquest","show_current_screen_outline",ShowCurScreenOutline);
1688 return D_O_K;
1689 }
1690
1691 int32_t onToggleShowScripts()
1692 {
1693 ShowFFScripts=!ShowFFScripts;
1694 zc_set_config("zquest","showffscripts",ShowFFScripts);
1695 return D_O_K;
1696 }
1697
1698 int32_t onToggleShowFFCs()
1699 {
1700 ShowFFCs=!ShowFFCs;
1701 zc_set_config("zquest","showffcs",ShowFFCs);
1702 return D_O_K;
1703 }
1704
1705 int32_t onToggleShowSquares()
1706 {
1707 ShowSquares=!ShowSquares;
1708 zc_set_config("zquest","showsquares",ShowSquares);
1709 return D_O_K;
1710 }
1711
1712 int32_t onToggleShowInfo()
1713 {
1714 ShowInfo=!ShowInfo;
1715 zc_set_config("zquest","showinfo",ShowInfo);
1716 return D_O_K;
1717 }
1718
1719 int32_t onToggleHighlightLayer()
1720 {
1721 ActiveLayerHighlight = ActiveLayerHighlight ? 0 : 1;
1722 zc_set_config("zquest","hl_active_lyr",ActiveLayerHighlight);
1723 return D_O_K;
1724 }
1725
1726 int onKeySlash()
1727 {
1728 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1729 {
1730 onAbout();
1731 }
1732 return D_O_K;
1733 }
1734
1735 int onAKey()
1736 {
1737 if(prv_mode)
1738 Map.set_prvadvance(1);
1739 return D_O_K;
1740 }
1741
1742 int onReloadPreview()
1743 {
1744 if(prv_mode)
1745 {
1746 Map.set_prvscr(Map.get_prv_map(), Map.get_prv_scr());
1747 Map.set_prvcmb(0);
1748 }
1749 return D_O_K;
1750 }
1751 int onSecretsPreview()
1752 {
1753 if(prv_mode)
1754 {
1755 Map.prv_secrets(false);
1756 refresh(rALL);
1757 }
1758 return D_O_K;
1759 }
1760
1761 int onSKey()
1762 {
1763 if(CHECK_CTRL_CMD)
1764 {
1765 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1766 {
1767 onSaveAs();
1768 }
1769 else
1770 {
1771 if(!saved)
1772 onSave();
1773 }
1774 }
1775 else if(prv_mode)
1776 {
1777 Map.prv_secrets(false);
1778 refresh(rALL);
1779 }
1780 else onStrings();
1781 return D_O_K;
1782 }
1783 int onSetNewLayer(int newlayer)
1784 {
1785 CurrentLayer = newlayer;
1786 refresh(rALL);
1787 return D_O_K;
1788 }
1789 void lpal_dsa()
1790 {
1791 info_dsa("Level Palette Shortcuts",
1792 "You currently have level palette shortcuts disabled."
1793 " These can be re-enabled in 'Etc->Options', on the toggle 'Disable Level Palette Shortcuts'.",
1794 "dsa_lpal");
1795 }
1796 int onScreenLPal(int lpal)
1797 {
1798 if(DisableLPalShortcuts)
1799 {
1800 lpal_dsa();
1801 return D_O_K;
1802 }
1803 mark_save_dirty();
1804 Map.setcolor(lpal);
1805 refresh(rSCRMAP);
1806 return D_O_K;
1807 }
1808
1809 int32_t onPressEsc()
1810 {
1811 if(zoomed_minimap)
1812 mmap_set_zoom(false);
1813 else return onExit();
1814 return D_O_K;
1815 }
1816
1817 static DIALOG dialogs[] =
1818 {
1819 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
1820 { d_nbmenu_proc, 0, 0, 0, 13, 0, 0, 0, D_USER, 0, 0, (void *) &the_menu, NULL, NULL },
1821 { d_zq_hotkey_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1822
1823 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
1824 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_ESC, 0, (void *) onPressEsc, NULL, NULL },
1825 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, (void *) onUsedCombos, NULL, NULL },
1826 { d_vsync_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1827 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1828 };
1829
1830
1831 int32_t onDecColour()
1832 {
1833 if ( CHECK_CTRL_CMD )
1834 {
1835 return onDecScrPal16();
1836 }
1837
1838 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1839 {
1840 return onDecScrPal();
1841 }
1842
1843 else
1844 {
1845 return onDecreaseCSet();
1846 }
1847 }
1848
1849 int32_t onIncColour()
1850 {
1851
1852 if ( CHECK_CTRL_CMD )
1853 {
1854 return onIncScrPal16();
1855 }
1856
1857 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1858 {
1859 return onIncScrPal();
1860 }
1861
1862 else
1863 {
1864 return onIncreaseCSet();
1865 }
1866 }
1867
1868 static DIALOG save_tiles_dlg[] =
1869 {
1870 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1871
1872
1873 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Tile Pack", NULL, NULL },
1874 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1875 //for future tabs
1876 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1877 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1878 //4
1879 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
1880 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1881 //6
1882 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
1883 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1884 //8
1885 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
1886 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1887 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1888 };
1889
1890
1891 void savesometiles(const char *prompt,int32_t initialval)
1892 {
1893
1894 char firsttile[8], tilecount[8];
1895 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
1896 sprintf(firsttile,"%d",0);
1897 sprintf(tilecount,"%d",1);
1898 //int32_t ret;
1899
1900
1901
1902 save_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
1903
1904 sprintf(firsttile,"%d",0);
1905 sprintf(tilecount,"%d",1);
1906
1907 save_tiles_dlg[5].dp = firsttile;
1908 save_tiles_dlg[7].dp = tilecount;
1909
1910 large_dialog(save_tiles_dlg);
1911
1912 int32_t ret = do_zqdialog(save_tiles_dlg,-1);
1913 jwin_center_dialog(save_tiles_dlg);
1914
1915 if(ret == 8)
1916 {
1917 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
1918 the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
1919 if(prompt_for_new_file_compat("Save ZTILE(.ztile)", "ztile", NULL,datapath,false))
1920 {
1921 char name[PATH_MAX];
1922 extract_name(temppath,name,FILENAMEALL);
1923 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
1924 if(f)
1925 {
1926 writetilefile(f,first_tile_id,the_tile_count);
1927 pack_fclose(f);
1928 displayinfo("Success!",fmt::format("Saved {}",name));
1929 }
1930 }
1931 }
1932 }
1933
1934 static DIALOG read_tiles_dlg[] =
1935 {
1936 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1937
1938
1939 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Tilepack To:", NULL, NULL },
1940 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1941 //for future tabs
1942 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1943 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1944 //4
1945 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
1946 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1947 //6
1948 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
1949 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1950 //8
1951 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
1952 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1953 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1954 };
1955
1956
1957 void writesometiles_to(const char *prompt,int32_t initialval)
1958 {
1959
1960 char firsttile[8];;
1961 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
1962 sprintf(firsttile,"%d",0);
1963 //int32_t ret;
1964
1965
1966
1967 read_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
1968
1969 sprintf(firsttile,"%d",0);
1970 //sprintf(tilecount,"%d",1);
1971
1972 read_tiles_dlg[5].dp = firsttile;
1973
1974 large_dialog(read_tiles_dlg);
1975
1976 int32_t ret = do_zqdialog(read_tiles_dlg,-1);
1977 jwin_center_dialog(read_tiles_dlg);
1978
1979 if(ret == 8)
1980 {
1981 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
1982 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
1983 if(prompt_for_existing_file_compat("Load ZTILE(.ztile)", "ztile", NULL,datapath,false))
1984 {
1985
1986 char name[256];
1987 extract_name(temppath,name,FILENAMEALL);
1988 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
1989 if(f)
1990 {
1991
1992 if (!readtilefile_to_location(f,first_tile_id))
1993 {
1994 al_trace("Could not read from .ztile packfile %s\n", name);
1995 displayinfo("ZTILE File: Error","Could not load the specified Tile.");
1996 }
1997 else
1998 {
1999 displayinfo("ZTILE File: Success!","Loaded the source tiles to your tile sheets!");
2000 }
2001 pack_fclose(f);
2002 }
2003 }
2004 }
2005 }
2006
2007
2008 static DIALOG save_combofiles_dlg[] =
2009 {
2010 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2011
2012
2013 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Pack", NULL, NULL },
2014 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2015 //for future tabs
2016 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2017 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2018 //4
2019 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2020 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2021 //6
2022 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2023 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2024 //8
2025 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2026 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2027 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2028 };
2029
2030
2031 void savesomecombos(const char *prompt,int32_t initialval)
2032 {
2033
2034 char firsttile[8], tilecount[8];
2035 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2036 sprintf(firsttile,"%d",0);
2037 sprintf(tilecount,"%d",1);
2038 //int32_t ret;
2039
2040
2041
2042 save_combofiles_dlg[0].dp2 = get_zc_font(font_lfont);
2043
2044 sprintf(firsttile,"%d",0);
2045 sprintf(tilecount,"%d",1);
2046
2047 save_combofiles_dlg[5].dp = firsttile;
2048 save_combofiles_dlg[7].dp = tilecount;
2049
2050 large_dialog(save_combofiles_dlg);
2051
2052 int32_t ret = do_zqdialog(save_combofiles_dlg,-1);
2053 jwin_center_dialog(save_combofiles_dlg);
2054
2055 if(ret == 8)
2056 {
2057 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2058 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOS-1)-first_tile_id);
2059 if(prompt_for_new_file_compat("Save ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2060 {
2061 char name[PATH_MAX];
2062 extract_name(temppath,name,FILENAMEALL);
2063 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2064 if(f)
2065 {
2066 writecombofile(f,first_tile_id,the_tile_count);
2067 pack_fclose(f);
2068 displayinfo("Success!",fmt::format("Saved {}",name));
2069 }
2070 }
2071 }
2072 }
2073
2074
2075 static DIALOG load_comboset_dlg[] =
2076 {
2077 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2078
2079
2080 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Set (Range)", NULL, NULL },
2081 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2082 //for future tabs
2083 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2084 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2085 //4
2086 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2087 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2088 //6
2089 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2090 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2091 //8
2092 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2093 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2094 { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2095
2096 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2097 };
2098
2099 void writesomecombos(const char *prompt,int32_t initialval)
2100 {
2101
2102 char firsttile[8];
2103 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2104 sprintf(firsttile,"%d",0);
2105 //int32_t ret;
2106
2107
2108
2109 load_comboset_dlg[0].dp2 = get_zc_font(font_lfont);
2110
2111 sprintf(firsttile,"%d",0);
2112 //sprintf(tilecount,"%d",1);
2113
2114 load_comboset_dlg[5].dp = firsttile;
2115
2116 byte nooverwrite = 0;
2117
2118
2119 large_dialog(load_comboset_dlg);
2120
2121 int32_t ret = do_zqdialog(load_comboset_dlg,-1);
2122 jwin_center_dialog(load_comboset_dlg);
2123
2124 if(ret == 8)
2125 {
2126 if (load_comboset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2127
2128 al_trace("Nooverwrite is: %d\n", nooverwrite);
2129 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2130 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2131 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2132 {
2133 char name[256];
2134 extract_name(temppath,name,FILENAMEALL);
2135 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2136 if(f)
2137 {
2138
2139 if (!readcombofile(f,first_tile_id,nooverwrite))
2140 {
2141 al_trace("Could not read from .zcombo packfile %s\n", name);
2142 displayinfo("ZCOMBO File: Error","Could not load the specified combos.");
2143 }
2144 else
2145 {
2146 displayinfo("ZCOMBO File: Success!","Loaded the source combos to your combo pages!");
2147 mark_save_dirty();
2148 }
2149 pack_fclose(f);
2150 }
2151
2152 }
2153 }
2154 }
2155
2156 static DIALOG load_combopack_dlg[] =
2157 {
2158 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2159
2160
2161 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import Full Combo Package 1:1", NULL, NULL },
2162 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2163 //for future tabs
2164 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2165 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2166 //4
2167 { d_dummy_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2168 { d_dummy_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2169 //6
2170 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2171 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2172 //8
2173 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2174 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2175 { jwin_check_proc, 10, 42, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2176
2177 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2178 };
2179
2180 void loadcombopack(const char *prompt,int32_t initialval)
2181 {
2182
2183 char firsttile[8];
2184 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2185 sprintf(firsttile,"%d",0);
2186 //int32_t ret;
2187
2188
2189
2190 load_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2191
2192 sprintf(firsttile,"%d",0);
2193 //sprintf(tilecount,"%d",1);
2194
2195 load_combopack_dlg[5].dp = firsttile;
2196
2197 byte nooverwrite = 0;
2198
2199
2200 large_dialog(load_combopack_dlg);
2201
2202 int32_t ret = do_zqdialog(load_combopack_dlg,-1);
2203 jwin_center_dialog(load_combopack_dlg);
2204
2205 if(ret == 8)
2206 {
2207 if (load_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2208
2209 al_trace("Nooverwrite is: %d\n", nooverwrite);
2210 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2211 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2212 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2213 {
2214 char name[256];
2215 extract_name(temppath,name,FILENAMEALL);
2216 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2217 if(f)
2218 {
2219 //need dialogue here
2220 if (!readcombofile(f,0,nooverwrite))
2221 {
2222 al_trace("Could not read from .zcombo packfile %s\n", name);
2223 displayinfo("ZCOMBO File: Error","Could not load the specified Tile.");
2224 }
2225 else
2226 {
2227 displayinfo("ZCOMBO File: Success!","Loaded the source combos to your combo pages!");
2228 mark_save_dirty();
2229 }
2230 }
2231
2232 pack_fclose(f);
2233 }
2234 }
2235 }
2236
2237
2238 static DIALOG read_combopack_dlg[] =
2239 {
2240 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2241
2242
2243 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combos (Specific Dest)", NULL, NULL },
2244 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2245 //for future tabs
2246 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2247 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2248 //4
2249 { jwin_text_proc, 10, 24, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2250 { jwin_edit_proc, 55, 22, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2251 //6
2252 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2253 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2254 //8
2255 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2256 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2257 //10
2258 { jwin_check_proc, 10, 58, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2259 //11
2260 { jwin_text_proc, 10, 42, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Skip:", NULL, NULL },
2261 //12
2262 { jwin_edit_proc, 55, 40, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2263
2264 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2265 };
2266
2267
2268
2269 void writesomecombos_to(const char *prompt,int32_t initialval)
2270 {
2271
2272 char firsttile[8];
2273 char skiptile[8];
2274 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2275 sprintf(firsttile,"%d",0);
2276 //int32_t ret;
2277
2278
2279
2280 read_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2281
2282 sprintf(skiptile,"%d",0);
2283 //sprintf(tilecount,"%d",1);
2284
2285 read_combopack_dlg[5].dp = firsttile;
2286
2287 byte nooverwrite = 0;
2288 int32_t skipover = 0;
2289
2290 sprintf(skiptile,"%d",0);
2291 //sprintf(tilecount,"%d",1);
2292
2293 read_combopack_dlg[12].dp = skiptile;
2294
2295 large_dialog(read_combopack_dlg);
2296
2297 int32_t ret = do_zqdialog(read_combopack_dlg,-1);
2298 jwin_center_dialog(read_combopack_dlg);
2299
2300 if(ret == 8)
2301 {
2302 if (read_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2303
2304 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2305 skipover = vbound(atoi(skiptile), 0, (MAXCOMBOS-1));
2306 al_trace("skipover is: %d\n", skipover);
2307 //skipover = vbound(skipover, 0, (MAXCOMBOS-1-skipover));
2308 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2309 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2310 {
2311 char name[256];
2312 extract_name(temppath,name,FILENAMEALL);
2313 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2314 if(f)
2315 {
2316
2317 if (!readcombofile_to_location(f,first_tile_id,nooverwrite, skipover))
2318 {
2319 al_trace("Could not read from .zcombo packfile %s\n", name);
2320 displayinfo("ZCOMBO File: Error","Could not load the specified combos.");
2321 }
2322 else
2323 {
2324 displayinfo("ZCOMBO File: Success!","Loaded the source combos to your combo pages!");
2325 mark_save_dirty();
2326 }
2327 pack_fclose(f);
2328 }
2329
2330 }
2331 }
2332 }
2333
2334
2335
2336 static DIALOG save_dmaps_dlg[] =
2337 {
2338 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2339
2340
2341 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save DMaps (.zdmap)", NULL, NULL },
2342 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2343 //for future tabs
2344 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2345 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2346 //4
2347 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2348 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2349 //6
2350 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Last", NULL, NULL },
2351 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2352 //8
2353 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2354 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2355 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2356 };
2357
2358
2359 void savesomedmaps(const char *prompt,int32_t initialval)
2360 {
2361
2362 char firstdmap[8], lastdmap[8];
2363 int32_t first_dmap_id = 0; int32_t last_dmap_id = 0;
2364 sprintf(firstdmap,"%d",0);
2365 sprintf(lastdmap,"%d",1);
2366 //int32_t ret;
2367
2368
2369
2370 save_dmaps_dlg[0].dp2 = get_zc_font(font_lfont);
2371
2372 sprintf(firstdmap,"%d",0);
2373 sprintf(lastdmap,"%d",0);
2374
2375 save_dmaps_dlg[5].dp = firstdmap;
2376 save_dmaps_dlg[7].dp = lastdmap;
2377
2378 large_dialog(save_dmaps_dlg);
2379
2380 int32_t ret = do_zqdialog(save_dmaps_dlg,-1);
2381 jwin_center_dialog(save_dmaps_dlg);
2382
2383 if(ret == 8)
2384 {
2385 first_dmap_id = vbound(atoi(firstdmap), 0, MAXDMAPS-1);
2386 last_dmap_id = vbound(atoi(lastdmap), 0, MAXDMAPS-1);
2387
2388 if ( last_dmap_id < first_dmap_id )
2389 {
2390 int32_t swap = last_dmap_id;
2391 last_dmap_id = first_dmap_id;
2392 first_dmap_id = swap;
2393 }
2394 if(!prompt_for_new_file_compat("Export DMaps (.zdmap)","zdmap",NULL,datapath,false))
2395
2396
2397 mark_save_dirty();
2398
2399 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2400 if(f)
2401 {
2402 if(!writesomedmaps(f,first_dmap_id,last_dmap_id,MAXDMAPS))
2403 {
2404 char name[PATH_MAX];
2405 extract_name(temppath,name,FILENAMEALL);
2406 displayinfo("Error",fmt::format("Unable to load {}",name));
2407 }
2408 else
2409 {
2410 char name[PATH_MAX];
2411 extract_name(temppath,name,FILENAMEALL);
2412 displayinfo("Success!",fmt::format("Saved {}",name));
2413 }
2414 }
2415 pack_fclose(f);
2416 }
2417 }
2418
2419 static DIALOG save_comboaliasfiles_dlg[] =
2420 {
2421 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2422
2423
2424 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Alias Pack", NULL, NULL },
2425 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2426 //for future tabs
2427 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2428 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2429 //4
2430 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2431 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2432 //6
2433 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2434 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2435 //8
2436 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2437 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2438 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2439 };
2440
2441
2442 void savesomecomboaliases(const char *prompt,int32_t initialval)
2443 {
2444
2445 char firsttile[8], tilecount[8];
2446 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2447 sprintf(firsttile,"%d",0);
2448 sprintf(tilecount,"%d",1);
2449 //int32_t ret;
2450
2451
2452
2453 save_comboaliasfiles_dlg[0].dp2 = get_zc_font(font_lfont);
2454
2455 sprintf(firsttile,"%d",0);
2456 sprintf(tilecount,"%d",1);
2457
2458 save_comboaliasfiles_dlg[5].dp = firsttile;
2459 save_comboaliasfiles_dlg[7].dp = tilecount;
2460
2461 large_dialog(save_comboaliasfiles_dlg);
2462
2463 int32_t ret = do_zqdialog(save_comboaliasfiles_dlg,-1);
2464 jwin_center_dialog(save_comboaliasfiles_dlg);
2465
2466 if(ret == 8)
2467 {
2468 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2469 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOALIASES-1)-first_tile_id);
2470 if(prompt_for_new_file_compat("Save ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2471 {
2472 char name[PATH_MAX];
2473 extract_name(temppath,name,FILENAMEALL);
2474 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2475 if(f)
2476 {
2477 writecomboaliasfile(f,first_tile_id,the_tile_count);
2478 pack_fclose(f);
2479 displayinfo("Success!",fmt::format("Saved {}",name));
2480 }
2481 }
2482 }
2483 }
2484
2485
2486 static DIALOG read_comboaliaspack_dlg[] =
2487 {
2488 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2489
2490
2491 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combo Pack To:", NULL, NULL },
2492 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2493 //for future tabs
2494 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2495 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2496 //4
2497 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2498 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2499 //6
2500 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2501 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2502 //8
2503 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2504 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2505 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2506 };
2507
2508
2509 void writesomecomboaliases_to(const char *prompt,int32_t initialval)
2510 {
2511
2512 char firsttile[8];;
2513 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2514 sprintf(firsttile,"%d",0);
2515 //int32_t ret;
2516
2517
2518
2519 read_comboaliaspack_dlg[0].dp2 = get_zc_font(font_lfont);
2520
2521 sprintf(firsttile,"%d",0);
2522 //sprintf(tilecount,"%d",1);
2523
2524 read_comboaliaspack_dlg[5].dp = firsttile;
2525
2526 large_dialog(read_comboaliaspack_dlg);
2527
2528 int32_t ret = do_zqdialog(read_comboaliaspack_dlg,-1);
2529 jwin_center_dialog(read_comboaliaspack_dlg);
2530
2531 if(ret == 8)
2532 {
2533 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2534 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2535 if(prompt_for_existing_file_compat("Load ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2536 {
2537 char name[256];
2538 extract_name(temppath,name,FILENAMEALL);
2539 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2540 if(f)
2541 {
2542
2543 if (!readcomboaliasfile_to_location(f,first_tile_id))
2544 {
2545 al_trace("Could not read from .zcombo packfile %s\n", name);
2546 displayinfo("ZALIAS File: Error","Could not load the specified combo aliases.");
2547 }
2548 else
2549 {
2550 displayinfo("ZALIAS File: Success!","Loaded the source combos to your combo alias table!");
2551 mark_save_dirty();
2552 }
2553 pack_fclose(f);
2554 }
2555 }
2556 }
2557 }
2558
2559
2560
2561
2562 //Doorsets
2563
2564 static DIALOG save_doorset_dlg[] =
2565 {
2566 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2567 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Doorset", NULL, NULL },
2568 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2569 //for future tabs
2570 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2571 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2572 //4
2573 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2574 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2575 //6
2576 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2577 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2578 //8
2579 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2580 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2581 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2582 };
2583
2584
2585 void do_exportdoorset(const char *prompt,int32_t initialval)
2586 {
2587 char firstdoor[8], doorct[8];
2588 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2589 sprintf(firstdoor,"%d",0);
2590 sprintf(doorct,"%d",1);
2591 //int32_t ret;
2592 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2593
2594 sprintf(firstdoor,"%d",0);
2595 sprintf(doorct,"%d",1);
2596
2597 save_doorset_dlg[5].dp = firstdoor;
2598 save_doorset_dlg[7].dp = doorct;
2599
2600 large_dialog(save_doorset_dlg);
2601
2602 int32_t ret = do_zqdialog(save_doorset_dlg,-1);
2603 jwin_center_dialog(save_doorset_dlg);
2604
2605 if(ret == 8) //OK
2606 {
2607 /* sanity bounds
2608 first_doorset_id = vbound(atoi(firstdoor), 0, (MAXCOMBOS-1));
2609 the_doorset_count = vbound(atoi(doorct), 1, (MAXCOMBOS-1)-first_doorset_id);
2610 */
2611 if(prompt_for_new_file_compat("Save ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2612 {
2613 char name[256];
2614 extract_name(temppath,name,FILENAMEALL);
2615 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2616 if(f)
2617 {
2618 writezdoorsets(f,first_doorset_id,the_doorset_count);
2619 pack_fclose(f);
2620 displayinfo("Success!",fmt::format("Saved {}",name));
2621 }
2622 }
2623 }
2624 }
2625
2626 static DIALOG load_doorset_dlg[] =
2627 {
2628 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2629 { jwin_win_proc, 0, 0, 120, 124, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Door Set (Range)", NULL, NULL },
2630 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2631 //for future tabs
2632 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2633 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2634 //4
2635 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2636 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2637 //6
2638 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2639 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2640 //8
2641 { jwin_button_proc, 15, 92, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2642 { jwin_button_proc, 69, 92, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2643 //10
2644 { jwin_text_proc, 10, 64, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Dest", NULL, NULL },
2645 { jwin_edit_proc, 55, 63, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2646 //8
2647
2648 // { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2649
2650 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2651 };
2652
2653 void do_importdoorset(const char *prompt,int32_t initialval)
2654 {
2655
2656 char firstdoor[8], doorct[8], destid[8];
2657 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2658 int32_t the_dest_id = 0;
2659 sprintf(firstdoor,"%d",0);
2660 sprintf(doorct,"%d",1);
2661 sprintf(destid,"%d",0);
2662 //int32_t ret;
2663
2664 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2665
2666 load_doorset_dlg[5].dp = firstdoor;
2667 load_doorset_dlg[7].dp = doorct;
2668 load_doorset_dlg[11].dp = destid;
2669
2670 byte nooverwrite = 0;
2671
2672 large_dialog(load_doorset_dlg);
2673
2674 int32_t ret = do_zqdialog(load_doorset_dlg,-1);
2675 jwin_center_dialog(load_doorset_dlg);
2676
2677 if(ret == 8) //OK
2678 {
2679 //if (load_doorset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2680
2681 //sanity bound
2682 first_doorset_id = vbound(atoi(firstdoor), 0, door_combo_set_count);
2683 the_doorset_count = vbound(atoi(doorct), 1, door_combo_set_count);
2684 the_dest_id = vbound(atoi(destid), 0, door_combo_set_count);
2685 if(prompt_for_existing_file_compat("Load ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2686 {
2687 char name[256];
2688 extract_name(temppath,name,FILENAMEALL);
2689 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2690 if(f)
2691 {
2692 int32_t ret = readzdoorsets(f,first_doorset_id,the_doorset_count, the_dest_id);
2693
2694 if (!ret)
2695 {
2696 al_trace("Could not read from .zdoors packfile %s\n", name);
2697 displayinfo("ZDOORS File: Error","Could not load the specified doorsets.");
2698 }
2699 else if ( ret == 1 )
2700 {
2701 displayinfo("ZDOORS File: Success!","Loaded the source doorsets!");
2702 mark_save_dirty();
2703 }
2704 else if ( ret == 2 )
2705 {
2706 displayinfo("ZDOORS File: Issue:","Targets exceed doorset count!");
2707 mark_save_dirty();
2708 }
2709 pack_fclose(f);
2710 }
2711 }
2712 }
2713 }
2714
2715 void update_combo_cycling()
2716 {
2717 Map.update_combo_cycling();
2718 }
2719
2720 void update_freeform_combos()
2721 {
2722 Map.update_freeform_combos();
2723 }
2724
2725 bool layers_valid(mapscr *tempscr)
2726 {
2727 for(int32_t i=0; i<6; i++)
2728 {
2729 if(tempscr->layermap[i]>map_count)
2730 {
2731 return false;
2732 }
2733 }
2734
2735 return true;
2736 }
2737
2738 void fix_layers(mapscr *tempscr, bool showwarning)
2739 {
2740 char buf[80]="";
2741
2742 for(int32_t i=0; i<6; i++)
2743 {
2744 if(tempscr->layermap[i]>map_count)
2745 {
2746 strcat(buf, "%d ");
2747 sprintf(buf, buf, i+1);
2748 tempscr->layermap[i]=0;
2749 }
2750 }
2751
2752 if(showwarning)
2753 {
2754 displayinfo("Invalid layers detected",
2755 fmt::format("One or more layers on this screen used"
2756 "maps that do not exist. The settings of these"
2757 "layers have been changed: {}", buf));
2758 }
2759 }
2760
2761 extern const char *colorlist(int32_t index, int32_t *list_size);
2762
2763 static char autobackup_str_buf[32];
2764 const char *autobackuplist(int32_t index, int32_t *list_size)
2765 {
2766 if(index>=0)
2767 {
2768 bound(index,0,10);
2769
2770 if(index==0)
2771 {
2772 sprintf(autobackup_str_buf,"Disabled");
2773 }
2774 else
2775 {
2776 sprintf(autobackup_str_buf,"%2d",index);
2777 }
2778
2779 return autobackup_str_buf;
2780 }
2781
2782 *list_size=11;
2783 return NULL;
2784 }
2785
2786 static char autosave_str_buf[32];
2787 const char *autosavelist(int32_t index, int32_t *list_size)
2788 {
2789 if(index>=0)
2790 {
2791 bound(index,0,10);
2792
2793 if(index==0)
2794 {
2795 sprintf(autosave_str_buf,"Disabled");
2796 }
2797 else
2798 {
2799 sprintf(autosave_str_buf,"%2d Minute%c",index,index>1?'s':0);
2800 }
2801
2802 return autosave_str_buf;
2803 }
2804
2805 *list_size=11;
2806 return NULL;
2807 }
2808
2809 const char *autosavelist2(int32_t index, int32_t *list_size)
2810 {
2811 if(index>=0)
2812 {
2813 bound(index,0,9);
2814 sprintf(autosave_str_buf,"%2d",index+1);
2815 return autosave_str_buf;
2816 }
2817
2818 *list_size=10;
2819 return NULL;
2820 }
2821
2822
2823 static int32_t options_1_list[] =
2824 {
2825 // dialog control number
2826 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -1
2827 };
2828
2829 static int32_t options_2_list[] =
2830 {
2831 // dialog control number
2832 50, 51, -1
2833 };
2834
2835 static int32_t options_3_list[] =
2836 {
2837 // dialog control number
2838 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, -1
2839 };
2840 static int32_t options_4_list[] =
2841 {
2842 57, 58, 59, 60,
2843 -1
2844 };
2845
2846 static TABPANEL options_tabs[] =
2847 {
2848 // (text)
2849 { (char *)" 1 ", D_SELECTED, options_1_list, 0, NULL },
2850 { (char *)" 2 ", 0, options_2_list, 0, NULL },
2851 { (char *)" 3 ", 0, options_3_list, 0, NULL },
2852 { (char *)" 4 ", 0, options_4_list, 0, NULL },
2853 { NULL, 0, NULL, 0, NULL }
2854 };
2855
2856 12 static ListData autobackup_list(autobackuplist, &font);
2857 12 static ListData autosave_list(autosavelist, &font);
2858 12 static ListData autosave_list2(autosavelist2, &font);
2859 12 static ListData color_list(colorlist, &font);
2860 12 static ListData snapshotformat_list(snapshotformatlist, &font);
2861
2862 const char *dm_names[dm_max]=
2863 {
2864 "Normal",
2865 "Relational", // Removed.
2866 "Dungeon", // Removed.
2867 "Alias",
2868 "Pool",
2869 "Auto"
2870 };
2871
2872 void fix_drawing_mode_menu()
2873 {
2874 drawing_mode_menu.select_only_uid(draw_mode);
2875 }
2876
2877 int32_t onDrawingMode()
2878 {
2879 draw_mode=(draw_mode+1)%dm_max;
2880 int dm_relational = 1;
2881 if ((int)draw_mode == dm_relational)
2882 draw_mode += 2;
2883 fix_drawing_mode_menu();
2884 restore_mouse();
2885 return D_O_K;
2886 }
2887
2888 int32_t onDrawingModeNormal()
2889 {
2890 draw_mode=dm_normal;
2891 fix_drawing_mode_menu();
2892 restore_mouse();
2893 return D_O_K;
2894 }
2895
2896 int32_t onDrawingModeAlias()
2897 {
2898 if(draw_mode==dm_alias)
2899 {
2900 return onDrawingModeNormal();
2901 }
2902
2903 draw_mode=dm_alias;
2904 alias_cset_mod=0;
2905 fix_drawing_mode_menu();
2906 restore_mouse();
2907 return D_O_K;
2908 }
2909
2910 int32_t onDrawingModePool()
2911 {
2912 if(draw_mode==dm_cpool)
2913 {
2914 return onDrawingModeNormal();
2915 }
2916
2917 draw_mode=dm_cpool;
2918 fix_drawing_mode_menu();
2919 restore_mouse();
2920 return D_O_K;
2921 }
2922
2923 int32_t onDrawingModeAuto()
2924 {
2925 if (draw_mode == dm_auto)
2926 {
2927 return onDrawingModeNormal();
2928 }
2929
2930 draw_mode = dm_auto;
2931 fix_drawing_mode_menu();
2932 restore_mouse();
2933 return D_O_K;
2934 }
2935
2936 int32_t onReTemplate()
2937 {
2938 if (alert_confirm("Confirm Overwrite","Apply NES Dungeon template to all screens on this map?"))
2939 {
2940 Map.TemplateAll();
2941 refresh(rALL);
2942 }
2943
2944 return D_O_K;
2945 }
2946
2947 int32_t onUndo()
2948 {
2949 Map.UndoCommand();
2950 refresh(rALL);
2951 return D_O_K;
2952 }
2953
2954 int32_t onRedo()
2955 {
2956 Map.RedoCommand();
2957 refresh(rALL);
2958 return D_O_K;
2959 }
2960
2961 int32_t onCopy()
2962 {
2963 if(prv_mode)
2964 {
2965 Map.set_prvcmb(Map.get_prvcmb()==0?1:0);
2966 return D_O_K;
2967 }
2968
2969 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
2970 Map.Copy(screen);
2971 return D_O_K;
2972 }
2973
2974 int32_t onPaste()
2975 {
2976 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
2977 {
2978 if(CHECK_CTRL_CMD)
2979 return onPasteAllToAll();
2980 else return onPasteAll();
2981 }
2982 else if(CHECK_CTRL_CMD)
2983 return onPasteToAll();
2984 else
2985 {
2986 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
2987 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartial, screen);
2988 }
2989 return D_O_K;
2990 }
2991
2992 int32_t onPasteAll()
2993 {
2994 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
2995 Map.DoPasteScreenCommand(PasteCommandType::ScreenAll, screen);
2996 return D_O_K;
2997 }
2998
2999 int32_t onPasteToAll()
3000 {
3001 if(alert_confirm("Confirmation", "You are about to paste to all screens on the current map.\nAre you sure?"))
3002 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartialToEveryScreen);
3003 return D_O_K;
3004 }
3005
3006 int32_t onPasteAllToAll()
3007 {
3008 if(alert_confirm("Confirmation", "You are about to paste to all screens on the current map.\nAre you sure?"))
3009 Map.DoPasteScreenCommand(PasteCommandType::ScreenAllToEveryScreen);
3010 return D_O_K;
3011 }
3012
3013 int32_t onPasteUnderCombo()
3014 {
3015 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3016 Map.DoPasteScreenCommand(PasteCommandType::ScreenUnderCombo, screen);
3017 return D_O_K;
3018 }
3019
3020 int32_t onPasteSecretCombos()
3021 {
3022 Map.DoPasteScreenCommand(PasteCommandType::ScreenSecretCombos);
3023 return D_O_K;
3024 }
3025
3026 int32_t onPasteFFCombos()
3027 {
3028 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3029 Map.DoPasteScreenCommand(PasteCommandType::ScreenFFCombos, screen);
3030 return D_O_K;
3031 }
3032
3033 int32_t onPasteWarps()
3034 {
3035 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3036 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarps, screen);
3037 return D_O_K;
3038 }
3039
3040 int32_t onPasteScreenData()
3041 {
3042 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3043 Map.DoPasteScreenCommand(PasteCommandType::ScreenData, screen);
3044 return D_O_K;
3045 }
3046
3047 int32_t onPasteWarpLocations()
3048 {
3049 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3050 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarpLocations, screen);
3051 return D_O_K;
3052 }
3053
3054 int32_t onPasteDoors()
3055 {
3056 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3057 Map.DoPasteScreenCommand(PasteCommandType::ScreenDoors, screen);
3058 return D_O_K;
3059 }
3060
3061 int32_t onPasteLayers()
3062 {
3063 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3064 Map.DoPasteScreenCommand(PasteCommandType::ScreenLayers, screen);
3065 return D_O_K;
3066 }
3067
3068 int32_t onPastePalette()
3069 {
3070 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3071 Map.DoPasteScreenCommand(PasteCommandType::ScreenPalette, screen);
3072 return D_O_K;
3073 }
3074
3075 int32_t onPasteRoom()
3076 {
3077 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3078 Map.DoPasteScreenCommand(PasteCommandType::ScreenRoom, screen);
3079 return D_O_K;
3080 }
3081
3082 int32_t onPasteGuy()
3083 {
3084 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3085 Map.DoPasteScreenCommand(PasteCommandType::ScreenGuy, screen);
3086 return D_O_K;
3087 }
3088
3089 int32_t onPasteEnemies()
3090 {
3091 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3092 Map.DoPasteScreenCommand(PasteCommandType::ScreenEnemies, screen);
3093 return D_O_K;
3094 }
3095
3096 int32_t onDelete()
3097 {
3098 restore_mouse();
3099
3100 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3101 mapscr* scr = active_visible_screen ? active_visible_screen->scr : Map.CurrScr();
3102 if(!(scr->valid&mVALID) || alert_confirm("Confirm Delete","Delete this screen?"))
3103 {
3104 Map.DoClearScreenCommand(screen);
3105 }
3106
3107 mark_save_dirty();
3108 return D_O_K;
3109 }
3110
3111 int32_t onDeleteMap()
3112 {
3113 if (alert_confirm("Confirm Delete","Clear this entire map?"))
3114 {
3115 Map.clearmap(false);
3116 refresh(rALL);
3117 mark_save_dirty();
3118 }
3119
3120 return D_O_K;
3121 }
3122
3123 int32_t onToggleDarkness()
3124 {
3125 Map.CurrScr()->flags^=4;
3126 refresh(rMAP+rMENU);
3127 mark_save_dirty();
3128 return D_O_K;
3129 }
3130
3131 int32_t onIncMap()
3132 {
3133 int32_t m=Map.getCurrMap();
3134 Map.setCurrMap(m+1>=map_count?0:m+1);
3135 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3136
3137 refresh(rALL);
3138 return D_O_K;
3139 }
3140
3141 int32_t onDecMap()
3142 {
3143 int32_t m = Map.getCurrMap();
3144 Map.setCurrMap((m-1<0)?map_count-1:zc_min(m-1,map_count-1));
3145 // Map.setCurrScr(Map.getCurrScr()); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3146 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3147
3148 Map.refresh_color();
3149
3150 refresh(rALL);
3151 return D_O_K;
3152 }
3153
3154
3155 int32_t onDefault_Pals()
3156 {
3157 if (alert_confirm("Confirm Reset","Reset all palette data?"))
3158 {
3159 mark_save_dirty();
3160
3161 if(!init_colordata(true, &header, &QMisc))
3162 {
3163 displayinfo("Error","Palette reset failed.");
3164 }
3165
3166 refresh_pal();
3167 }
3168
3169 return D_O_K;
3170 }
3171
3172 int32_t onDefault_Combos()
3173 {
3174 if (alert_confirm("Confirm Reset","Reset combo data?"))
3175 {
3176 mark_save_dirty();
3177
3178 if(!init_combos(true, &header))
3179 {
3180 displayinfo("Error","Combo reset failed.");
3181 }
3182
3183 refresh(rALL);
3184 }
3185
3186 return D_O_K;
3187 }
3188
3189 int32_t onDefault_Items()
3190 {
3191 if (alert_confirm("Confirm Reset","Reset all items?"))
3192 {
3193 mark_save_dirty();
3194 reset_items(true, &header);
3195 }
3196
3197 return D_O_K;
3198 }
3199
3200 int32_t onDefault_Weapons()
3201 {
3202 if (alert_confirm("Confirm Reset","Reset weapon/misc. sprite data?"))
3203 {
3204 mark_save_dirty();
3205 reset_wpns(true, &header);
3206 }
3207
3208 return D_O_K;
3209 }
3210
3211 int32_t onDefault_Guys()
3212 {
3213 if (alert_confirm("Confirm Reset","Reset all enemy/NPC data?"))
3214 {
3215 mark_save_dirty();
3216 reset_guys();
3217 }
3218
3219 return D_O_K;
3220 }
3221
3222
3223 int32_t onDefault_Tiles()
3224 {
3225 if (alert_confirm("Confirm Reset","Reset all tiles?"))
3226 {
3227 mark_save_dirty();
3228
3229 if(!init_tiles(true, &header))
3230 {
3231 displayinfo("Error","Tile reset failed.");
3232 }
3233
3234 refresh(rALL);
3235 }
3236
3237 return D_O_K;
3238 }
3239
3240 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2);
3241
3242 int32_t onDefault_SFX()
3243 {
3244 if (alert_confirm("Confirm Reset", "Reset all sound effects?"))
3245 {
3246 mark_save_dirty();
3247 SAMPLE *temp_sample;
3248
3249 for(int32_t i=1; i<WAV_COUNT; i++)
3250 {
3251 temp_sample = (SAMPLE *)sfxdata[zc_min(i,Z35)].dat;
3252 change_sfx(&customsfxdata[i], temp_sample);
3253 sprintf(sfx_string[i],"s%03d",i);
3254
3255 if(i<Z35)
3256 strcpy(sfx_string[i], old_sfx_string[i-1]);
3257 set_bit(customsfxflag, i<Z35?1:0, i-1);
3258 }
3259 }
3260
3261 return D_O_K;
3262 }
3263
3264
3265 int32_t onDefault_MapStyles()
3266 {
3267 if (alert_confirm("Confirm Reset", "Reset all map styles?"))
3268 {
3269 mark_save_dirty();
3270 reset_mapstyles(true, &QMisc);
3271 }
3272
3273 return D_O_K;
3274 }
3275
3276 int onScrollScreen(int dir, bool warp)
3277 {
3278 Map.scroll(dir,warp);
3279 return D_O_K;
3280 }
3281
3282 int32_t onComboColLeft()
3283 {
3284 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3285 ;
3286 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3287 {
3288 First[current_combolist]-=1;
3289 clear_tooltip();
3290 refresh(rCOMBOS);
3291 }
3292 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3293 {
3294 combo_alistpos[current_comboalist]-=1;
3295 clear_tooltip();
3296 refresh(rCOMBOS);
3297 }
3298
3299 clear_keybuf();
3300 return D_O_K;
3301 }
3302
3303 int32_t onComboColRight()
3304 {
3305 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3306 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3307 ;
3308 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3309 {
3310 First[current_combolist]+=1;
3311 clear_tooltip();
3312 refresh(rCOMBOS);
3313 }
3314 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))&&(draw_mode==dm_alias))
3315 {
3316 combo_alistpos[current_comboalist]+=1;
3317 clear_tooltip();
3318 refresh(rCOMBOS);
3319 }
3320
3321 clear_keybuf();
3322 return D_O_K;
3323 }
3324
3325 int32_t onComboColUp()
3326 {
3327 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3328 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3329 ;
3330 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3331 {
3332 First[current_combolist]-=zc_min(First[current_combolist],sqr.w);
3333 clear_tooltip();
3334
3335 refresh(rCOMBOS);
3336 }
3337 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3338 {
3339 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],sqr.w);
3340 clear_tooltip();
3341 refresh(rCOMBOS);
3342 }
3343
3344 clear_keybuf();
3345 return D_O_K;
3346 }
3347
3348 int32_t onComboColDown()
3349 {
3350 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3351
3352 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3353 ;
3354 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3355 {
3356 First[current_combolist]+=zc_min((MAXCOMBOS-sqr.w)-First[current_combolist],sqr.w);
3357 clear_tooltip();
3358 refresh(rCOMBOS);
3359 }
3360 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(comboaliaslist[0].w*comboaliaslist[0].h)))&&(draw_mode==dm_alias))
3361 {
3362 combo_alistpos[current_comboalist]+=zc_min((MAXCOMBOALIASES-sqr.w)-combo_alistpos[current_comboalist],sqr.w);
3363 clear_tooltip();
3364 refresh(rCOMBOS);
3365 }
3366
3367 clear_keybuf();
3368 return D_O_K;
3369 }
3370
3371 void scrollup(int j)
3372 {
3373 switch(draw_mode)
3374 {
3375 case dm_alias:
3376 {
3377 auto& sqr = comboaliaslist[j];
3378 if(combo_alistpos[j]>0)
3379 {
3380 if(CHECK_CTRL_CMD)
3381 {
3382 combo_alistpos[j]=0;
3383 clear_tooltip();
3384 }
3385 else
3386 {
3387 combo_alistpos[j]-=zc_min(combo_alistpos[j],(sqr.w*sqr.h));
3388 clear_tooltip();
3389 }
3390
3391 refresh(rCOMBOS);
3392 }
3393 break;
3394 }
3395 case dm_cpool:
3396 {
3397 auto& sqr = comboaliaslist[j];
3398 if(combo_pool_listpos[j]>0)
3399 {
3400 if(CHECK_CTRL_CMD)
3401 {
3402 combo_pool_listpos[j]=0;
3403 clear_tooltip();
3404 }
3405 else
3406 {
3407 combo_pool_listpos[j]-=zc_min(combo_pool_listpos[j],(sqr.w*sqr.h));
3408 clear_tooltip();
3409 }
3410
3411 refresh(rCOMBOS);
3412 }
3413 break;
3414 }
3415 case dm_auto:
3416 {
3417 auto& sqr = comboaliaslist[j];
3418 if (combo_auto_listpos[j] > 0)
3419 {
3420 if (CHECK_CTRL_CMD)
3421 {
3422 combo_auto_listpos[j] = 0;
3423 clear_tooltip();
3424 }
3425 else
3426 {
3427 combo_auto_listpos[j] -= zc_min(combo_auto_listpos[j], (sqr.w * sqr.h));
3428 clear_tooltip();
3429 }
3430
3431 refresh(rCOMBOS);
3432 }
3433 break;
3434 }
3435 default:
3436 {
3437 auto& sqr = combolist[j];
3438 if(First[j]>0)
3439 {
3440 if(CHECK_CTRL_CMD)
3441 {
3442 First[j]-=zc_min(First[j],256);
3443 clear_tooltip();
3444 }
3445 else
3446 {
3447 First[j]-=zc_min(First[j],(sqr.w*sqr.h));
3448 clear_tooltip();
3449 }
3450
3451 refresh(rCOMBOS);
3452 }
3453 break;
3454 }
3455 }
3456 }
3457 void scrolldown(int j)
3458 {
3459 switch(draw_mode)
3460 {
3461 case dm_alias:
3462 {
3463 auto& sqr = comboaliaslist[j];
3464 if(combo_alistpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3465 {
3466 if(CHECK_CTRL_CMD)
3467 {
3468 combo_alistpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3469 clear_tooltip();
3470 }
3471 else
3472 {
3473 combo_alistpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_alistpos[j]+(sqr.w*sqr.h));
3474 clear_tooltip();
3475 }
3476
3477 refresh(rCOMBOS);
3478 }
3479 break;
3480 }
3481 case dm_cpool:
3482 {
3483 auto& sqr = comboaliaslist[j];
3484 if(combo_pool_listpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3485 {
3486 if(CHECK_CTRL_CMD)
3487 {
3488 combo_pool_listpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3489 clear_tooltip();
3490 }
3491 else
3492 {
3493 combo_pool_listpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_pool_listpos[j]+(sqr.w*sqr.h));
3494 clear_tooltip();
3495 }
3496
3497 refresh(rCOMBOS);
3498 }
3499 break;
3500 }
3501 case dm_auto:
3502 {
3503 auto& sqr = comboaliaslist[j];
3504 if (combo_auto_listpos[j] < (MAXCOMBOALIASES - (sqr.w * sqr.h)))
3505 {
3506 if (CHECK_CTRL_CMD)
3507 {
3508 combo_auto_listpos[j] = MAXCOMBOALIASES - (sqr.w * sqr.h);
3509 clear_tooltip();
3510 }
3511 else
3512 {
3513 combo_auto_listpos[j] = zc_min((MAXCOMBOALIASES - (sqr.w * sqr.h)), combo_pool_listpos[j] + (sqr.w * sqr.h));
3514 clear_tooltip();
3515 }
3516
3517 refresh(rCOMBOS);
3518 }
3519 break;
3520 }
3521 default:
3522 {
3523 auto& sqr = combolist[j];
3524 if(First[j]<(MAXCOMBOS-(sqr.w*sqr.h)))
3525 {
3526 if(CHECK_CTRL_CMD)
3527 {
3528 First[j]=zc_min((MAXCOMBOS-sqr.w*sqr.h),First[j]+256);
3529 clear_tooltip();
3530 }
3531 else
3532 {
3533 First[j]=zc_min((MAXCOMBOS-(sqr.w*sqr.h)),First[j]+(sqr.w*sqr.h));
3534 clear_tooltip();
3535 }
3536
3537 refresh(rCOMBOS);
3538 }
3539 break;
3540 }
3541 }
3542 }
3543
3544 int32_t onPgUp()
3545 {
3546 switch(draw_mode)
3547 {
3548 case dm_alias:
3549 scrollup(current_comboalist);
3550 break;
3551 case dm_cpool:
3552 scrollup(current_cpoollist);
3553 break;
3554 case dm_auto:
3555 scrollup(current_cautolist);
3556 break;
3557 default:
3558 scrollup(current_combolist);
3559 break;
3560 }
3561 return D_O_K;
3562 }
3563
3564 int32_t onPgDn()
3565 {
3566 switch(draw_mode)
3567 {
3568 case dm_alias:
3569 scrolldown(current_comboalist);
3570 break;
3571 case dm_cpool:
3572 scrolldown(current_cpoollist);
3573 break;
3574 case dm_auto:
3575 scrolldown(current_cautolist);
3576 break;
3577 default:
3578 scrolldown(current_combolist);
3579 break;
3580 }
3581 return D_O_K;
3582 }
3583
3584 int32_t onIncreaseCSet()
3585 {
3586 if(draw_mode!=dm_alias)
3587 {
3588 CSet=wrap(CSet+1,0,13);
3589 refresh(rCOMBOS+rMENU+rCOMBO);
3590 }
3591 else
3592 {
3593 alias_cset_mod=wrap(alias_cset_mod+1,0,13);
3594 }
3595 return D_O_K;
3596 }
3597
3598 int32_t onDecreaseCSet()
3599 {
3600 if(draw_mode!=dm_alias)
3601 {
3602 CSet=wrap(CSet-1,0,13);
3603 refresh(rCOMBOS+rMENU+rCOMBO);
3604 }
3605 else
3606 {
3607 alias_cset_mod=wrap(alias_cset_mod-1,0,13);
3608 }
3609 return D_O_K;
3610 }
3611
3612 int32_t onGotoPage()
3613 {
3614 if (draw_mode==dm_alias)
3615 {
3616 static const int PER_PAGE = 260;
3617 if(optional<int> v = call_get_num("Scroll to Alias Page", 0, MAXCOMBOALIASES/PER_PAGE-1, 0))
3618 combo_alistpos[current_comboalist] = *v*PER_PAGE;
3619 }
3620 else if (draw_mode==dm_cpool)
3621 {
3622 static const int PER_PAGE = 260;
3623 if(optional<int> v = call_get_num("Scroll to Combo Pool Page", 0, MAXCOMBOPOOLS/PER_PAGE-1, 0))
3624 combo_pool_listpos[current_cpoollist] = *v*PER_PAGE;
3625 }
3626 else if (draw_mode == dm_auto)
3627 {
3628 static const int PER_PAGE = 260;
3629 if(optional<int> v = call_get_num("Scroll to Auto Combo Page", 0, MAXAUTOCOMBOS/PER_PAGE-1, 0))
3630 combo_auto_listpos[current_cautolist] = *v*PER_PAGE;
3631 }
3632 else
3633 {
3634 static const int PER_PAGE = 256;
3635 if(optional<int> v = call_get_num("Scroll to Combo Page", 0, MAXCOMBOS/PER_PAGE-1, 0))
3636 First[current_combolist] = *v*PER_PAGE;
3637 }
3638
3639 return D_O_K;
3640 }
3641
3642 static char track_number_str_buf[MIDI_TRACK_BUFFER_SIZE] = {0};
3643 const char *tracknumlist(int32_t index, int32_t *list_size)
3644 {
3645 //memset(track_number_str_buf,0,50);
3646 if(index>=0)
3647 {
3648 bound(index,0,255);
3649 std::string name = zcmusic_get_track_name(zcmusic, index);
3650 sprintf(track_number_str_buf,"%02d %s",index+1, name.c_str());
3651 return track_number_str_buf;
3652 }
3653
3654 *list_size=zcmusic_get_tracks(zcmusic);
3655 return NULL;
3656 }
3657
3658 12 static ListData tracknum_list(tracknumlist, &font);
3659
3660 static DIALOG change_track_dlg[] =
3661 {
3662 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
3663 12 { jwin_win_proc, 60-12, 40, 200-16, 72, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Track", NULL, NULL },
3664 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
3665 12 { jwin_droplist_proc, 72-12, 60+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &tracknum_list, NULL, NULL },
3666 12 { jwin_button_proc, 70, 87, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
3667 12 { jwin_button_proc, 150, 87, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
3668 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
3669 };
3670 // return list_dlg[2].d1;
3671
3672 int32_t changeTrack()
3673 {
3674 restore_mouse();
3675 change_track_dlg[0].dp2=get_zc_font(font_lfont);
3676 change_track_dlg[2].d1=gme_track;
3677
3678 large_dialog(change_track_dlg);
3679
3680 if(do_zqdialog(change_track_dlg,2)==3)
3681 {
3682 gme_track=change_track_dlg[2].d1;
3683 zcmusic_change_track(zcmusic, gme_track);
3684 }
3685
3686 return D_O_K;
3687 }
3688
3689 void set_media_tunes()
3690 {
3691 media_menu.select_uid(MENUID_MEDIA_TUNES, true);
3692 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
3693 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3694 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3695
3696 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3697 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3698 }
3699
3700 int32_t playMusic()
3701 {
3702 char *ext;
3703 bool ismidi=false;
3704 char allmusic_types[256];
3705 sprintf(allmusic_types, "%s;mid", zcmusic_types);
3706
3707 if(prompt_for_existing_file_compat("Load Music",(char*)allmusic_types,NULL,midipath,false))
3708 {
3709 strcpy(midipath,temppath);
3710
3711 ext=get_extension(midipath);
3712
3713 if(
3714 (stricmp(ext,"ogg")==0)||
3715 (stricmp(ext,"mp3")==0)||
3716 (stricmp(ext,"it")==0)||
3717 (stricmp(ext,"xm")==0)||
3718 (stricmp(ext,"s3m")==0)||
3719 (stricmp(ext,"mod")==0)||
3720 (stricmp(ext,"spc")==0)||
3721 (stricmp(ext,"gym")==0)||
3722 (stricmp(ext,"nsf")==0)||
3723 (stricmp(ext,"gbs")==0)||
3724 (stricmp(ext,"vgm")==0)
3725 )
3726 {
3727 ismidi=false;
3728 }
3729 else if((stricmp(ext,"mid")==0))
3730 {
3731 ismidi=true;
3732 }
3733 else
3734 {
3735 return D_O_K;
3736 }
3737
3738 zc_stop_midi();
3739
3740 if(zcmusic != NULL)
3741 {
3742 zcmusic_stop(zcmusic);
3743 zcmusic_unload_file(zcmusic);
3744 zcmusic = NULL;
3745 zcmixer->newtrack = NULL;
3746 }
3747
3748 if(ismidi)
3749 {
3750 packfile_password("");
3751 if((song=load_midi(midipath))!=NULL)
3752 {
3753 if(zc_play_midi(song,true)==0)
3754 {
3755 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3756 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3757 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3758 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3759
3760 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3761 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3762 }
3763 }
3764 }
3765 else
3766 {
3767 gme_track=0;
3768 zcmusic = (ZCMUSIC*)zcmusic_load_file(midipath);
3769
3770 if(zcmusic!=NULL)
3771 {
3772 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3773 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3774 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3775 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3776
3777 bool distrack = zcmusic_get_tracks(zcmusic)<2;
3778 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, distrack);
3779 disable_hotkey(ZQKEY_CHANGE_TRACK, distrack);
3780
3781 zcmusic_play(zcmusic, midi_volume);
3782 }
3783 }
3784 }
3785
3786 return D_O_K;
3787 }
3788
3789 int32_t playZCForever()
3790 {
3791 stopMusic();
3792
3793 zcmusic = zcmusic_load_file("assets/zc/ZC_Forever_HD.mp3");
3794 if (zcmusic)
3795 {
3796 zcmusic_play(zcmusic, midi_volume);
3797 set_media_tunes();
3798 }
3799 return D_O_K;
3800 }
3801
3802 // It took awhile to get these values right, so no meddlin'!
3803 int32_t playTune1()
3804 {
3805 return playTune(0);
3806 }
3807 int32_t playTune2()
3808 {
3809 return playTune(81);
3810 }
3811 int32_t playTune3()
3812 {
3813 return playTune(233);
3814 }
3815 int32_t playTune4()
3816 {
3817 return playTune(553);
3818 }
3819 int32_t playTune5()
3820 {
3821 return playTune(814);
3822 }
3823 int32_t playTune6()
3824 {
3825 return playTune(985);
3826 }
3827 int32_t playTune7()
3828 {
3829 return playTune(1153);
3830 }
3831 int32_t playTune8()
3832 {
3833 return playTune(1333);
3834 }
3835 int32_t playTune9()
3836 {
3837 return playTune(1556);
3838 }
3839 int32_t playTune10()
3840 {
3841 return playTune(1801);
3842 }
3843 int32_t playTune11()
3844 {
3845 return playTune(2069);
3846 }
3847 int32_t playTune12()
3848 {
3849 return playTune(2189);
3850 }
3851 int32_t playTune13()
3852 {
3853 return playTune(2569);
3854 }
3855 int32_t playTune14()
3856 {
3857 return playTune(2753);
3858 }
3859 int32_t playTune15()
3860 {
3861 return playTune(2856);
3862 }
3863 int32_t playTune16()
3864 {
3865 return playTune(3042);
3866 }
3867 int32_t playTune17()
3868 {
3869 return playTune(3125);
3870 }
3871 int32_t playTune18()
3872 {
3873 return playTune(3217);
3874 }
3875 int32_t playTune19()
3876 {
3877 return playTune(3296);
3878 }
3879
3880 int32_t playTune(int32_t pos)
3881 {
3882 zc_stop_midi();
3883
3884 if(zcmusic != NULL)
3885 {
3886 zcmusic_stop(zcmusic);
3887 zcmusic_unload_file(zcmusic);
3888 zcmusic = NULL;
3889 zcmixer->newtrack = NULL;
3890 }
3891
3892 if(zc_play_midi(asset_tunes_midi,true)==0)
3893 {
3894 zc_midi_seek(pos);
3895 set_media_tunes();
3896 }
3897
3898 return D_O_K;
3899 }
3900
3901 int32_t stopMusic()
3902 {
3903 zc_stop_midi();
3904
3905 if(zcmusic != NULL)
3906 {
3907 zcmusic_stop(zcmusic);
3908 zcmusic_unload_file(zcmusic);
3909 zcmusic = NULL;
3910 zcmixer->newtrack = NULL;
3911 }
3912
3913 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3914 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
3915 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3916 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3917
3918 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3919 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3920 return D_O_K;
3921 }
3922
3923 static int32_t gamemisc1_list[] =
3924 {
3925 5,6,7,8,
3926 9,10,11,12,
3927
3928 37,38,39,40,
3929 41,42,43,44,
3930
3931 71,72,73,74,
3932 75,76,77,78,
3933
3934 -1
3935 };
3936
3937 static int32_t gamemisc2_list[] =
3938 {
3939 13,14,15,16,
3940 17,18,19,20,
3941
3942 45,46,47,48,
3943 49,50,51,52,
3944
3945 79,80,81,82,
3946 83,84,85,86,
3947
3948 -1
3949 };
3950
3951 static int32_t gamemisc3_list[] =
3952 {
3953 21,22,23,24,
3954 25,26,27,28,
3955
3956 53,54,55,56,
3957 57,58,59,60,
3958
3959 87,88,89,90,
3960 91,92,93,94,
3961
3962 -1
3963 };
3964
3965 static int32_t gamemisc4_list[] =
3966 {
3967 29,30,31,32,
3968 33,34,35,36,
3969
3970 61,62,63,64,
3971 65,66,67,68,
3972
3973 95,96,97,98,
3974 99,100,101,102,
3975
3976 -1
3977 };
3978
3979 static TABPANEL gamemisc_tabs[] =
3980 {
3981 // (text)
3982 { (char *)" Misc[0-7] ", D_SELECTED, gamemisc1_list, 0, NULL },
3983 { (char *)" Misc[8-15] ", 0, gamemisc2_list, 0, NULL },
3984 { (char *)" Misc[16-23] ", 0, gamemisc3_list, 0, NULL },
3985 { (char *)" Misc[24-31] ", 0, gamemisc4_list, 0, NULL },
3986 { NULL, 0, NULL, 0, NULL }
3987 };
3988
3989 //to do: Make string boxes larger, and split into two tabs.
3990 static DIALOG gamemiscarray_dlg[] =
3991 {
3992 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
3993
3994 { jwin_win_proc, 0, 10, 310, 224, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Game->Misc[]", NULL, NULL },
3995 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
3996 { jwin_tab_proc, 3, 26, 304, 174, vc(14), vc(1), 0, 0, 1, 0, (void *) gamemisc_tabs, NULL, (void *)gamemiscarray_dlg },
3997 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
3998 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
3999
4000 //5
4001 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4002 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4003 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4004 //8
4005 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4006 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4007 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4008 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4009 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4010 //13
4011 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4012 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4013 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4014 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4015 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4016 //18
4017 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4018 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4019 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4020 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4021 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4022 //23
4023 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4024 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4025 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4026 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4027 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4028 //28
4029 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4030 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4031 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4032 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4033 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4034 //33
4035 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4036 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4037 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4038 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4039 //37
4040 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4041 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4042 //39
4043 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4044 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4045 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4046 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4047 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4048 //44
4049 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4050 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4051 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4052
4053 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4054 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4055 //49
4056 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4057 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4058 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4059 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4060 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4061 //54
4062 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4063 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4064 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4065 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4066 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4067 //59
4068 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4069 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4070 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4071 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4072 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4073 //64
4074 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4075 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4076 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4077 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4078 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4079 //69
4080 { jwin_button_proc, 70, 204, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4081 { jwin_button_proc, 170, 204, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4082
4083 //71
4084 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4085 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4086 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4087 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4088 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4089 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4090 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4091 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4092 //79
4093 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4094 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4095 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4096 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4097 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4098 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4099 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4100 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4101 //87
4102 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4103 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4104 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4105 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4106 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4107 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4108 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4109 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4110 //95
4111 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4112 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4113 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4114 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4115 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4116 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4117 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4118 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4119
4120 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4121 };
4122
4123 // +----------+
4124 // | |
4125 // | View Pic |
4126 // | |
4127 // | |
4128 // | |
4129 // +----------+
4130
4131 BITMAP *pic=NULL;
4132 BITMAP *bmap=NULL;
4133 PALETTE picpal;
4134 PALETTE mappal;
4135 int32_t picx=0,picy=0,mapx=0,mapy=0,pblack,pwhite;
4136
4137 double picscale=1.0,mapscale=1.0;
4138 bool vp_showpal=true, vp_showsize=true, vp_center=true;
4139
4140 //INLINE int32_t pal_sum(RGB p) { return p.r + p.g + p.b; }
4141
4142 void get_bw(RGB *pal,int32_t &black,int32_t &white)
4143 {
4144 black=white=1;
4145
4146 for(int32_t i=1; i<256; i++)
4147 {
4148 if(pal_sum(pal[i])<pal_sum(pal[black]))
4149 black=i;
4150
4151 if(pal_sum(pal[i])>pal_sum(pal[white]))
4152 white=i;
4153 }
4154 }
4155
4156 void draw_bw_mouse(int32_t white, int32_t old_mouse, int32_t new_mouse)
4157 {
4158 blit(mouse_bmp[old_mouse][0],mouse_bmp[new_mouse][0],0,0,0,0,16,16);
4159
4160 for(int32_t y=0; y<16; y++)
4161 {
4162 for(int32_t x=0; x<16; x++)
4163 {
4164 if(getpixel(mouse_bmp[new_mouse][0],x,y)!=0)
4165 {
4166 putpixel(mouse_bmp[new_mouse][0],x,y,white);
4167 }
4168 }
4169 }
4170 }
4171
4172 int32_t load_the_pic(BITMAP **dst, PALETTE dstpal)
4173 {
4174 PALETTE temppal;
4175
4176 for(int32_t i=0; i<256; i++)
4177 {
4178 temppal[i]=dstpal[i];
4179 dstpal[i]=RAMpal[i];
4180 }
4181
4182 // set up the new palette
4183 for(int32_t i=0; i<64; i++)
4184 {
4185 dstpal[i].r = i;
4186 dstpal[i].g = i;
4187 dstpal[i].b = i;
4188 }
4189
4190 zc_set_palette(dstpal);
4191
4192 BITMAP *graypic = create_bitmap_ex(8,screen->w,screen->h);
4193 int32_t _w = screen->w-1;
4194 int32_t _h = screen->h-1;
4195
4196 // gray scale the current frame
4197 for(int32_t y=0; y<_h; y++)
4198 {
4199 for(int32_t x=0; x<_w; x++)
4200 {
4201 int32_t c = screen->line[y][x];
4202 int32_t gray = zc_min((temppal[c].r*42 + temppal[c].g*75 + temppal[c].b*14) >> 7, 63);
4203 graypic->line[y][x] = gray;
4204 }
4205 }
4206
4207 blit(graypic,screen,0,0,0,0,screen->w,screen->h);
4208 destroy_bitmap(graypic);
4209 #ifdef __GNUC__
4210 #pragma GCC diagnostic ignored "-Wformat-overflow"
4211 #endif
4212 char extbuf[2][80];
4213 memset(extbuf[0],0,80);
4214 memset(extbuf[1],0,80);
4215 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4216 strcpy(extbuf[1], snapshotformat_str[0][1]);
4217
4218 for(int32_t i=1; i<ssfmtMAX; ++i)
4219 {
4220 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4221 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4222 }
4223
4224 sprintf(extbuf[0], "%s)", extbuf[0]);
4225 #ifdef __GNUC__
4226 #pragma GCC diagnostic pop
4227 #endif
4228
4229 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4230
4231 if(!gotit)
4232 {
4233 zc_set_palette(temppal);
4234 get_palette(dstpal);
4235 return 1;
4236 }
4237
4238 strcpy(imagepath,temppath);
4239
4240 if(*dst)
4241 {
4242 destroy_bitmap(*dst);
4243 }
4244
4245 for(int32_t i=0; i<256; i++)
4246 {
4247 dstpal[i].r = 0;
4248 dstpal[i].g = 0;
4249 dstpal[i].b = 0;
4250 }
4251
4252 *dst = load_bitmap(imagepath,picpal);
4253
4254 if(!*dst)
4255 {
4256 displayinfo("Error",fmt::format("Error loading image: {}",imagepath));
4257 return 2;
4258 }
4259
4260 // get_bw(picpal,pblack,pwhite);
4261 // draw_bw_mouse(pwhite);
4262 // gui_bg_color = pblack;
4263 // gui_fg_color = pwhite;
4264
4265 if(vp_center)
4266 {
4267 picx=picy=0;
4268 }
4269 else
4270 {
4271 picx=(*dst)->w-zq_screen_w;
4272 picy=(*dst)->h-zq_screen_h;
4273 }
4274
4275 return 0;
4276 }
4277 int load_the_pic_new(BITMAP **dst, PALETTE dstpal)
4278 {
4279 #ifdef __GNUC__
4280 #pragma GCC diagnostic ignored "-Wformat-overflow"
4281 #endif
4282 char extbuf[2][80];
4283 memset(extbuf[0],0,80);
4284 memset(extbuf[1],0,80);
4285 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4286 strcpy(extbuf[1], snapshotformat_str[0][1]);
4287
4288 for(int32_t i=1; i<ssfmtMAX; ++i)
4289 {
4290 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4291 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4292 }
4293
4294 sprintf(extbuf[0], "%s)", extbuf[0]);
4295 #ifdef __GNUC__
4296 #pragma GCC diagnostic pop
4297 #endif
4298
4299 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4300
4301 if(!gotit)
4302 return 1;
4303
4304 strcpy(imagepath,temppath);
4305
4306 if(*dst)
4307 destroy_bitmap(*dst);
4308
4309 for(int32_t i=0; i<256; i++)
4310 {
4311 dstpal[i].r = 0;
4312 dstpal[i].g = 0;
4313 dstpal[i].b = 0;
4314 }
4315
4316 *dst = load_bitmap(imagepath,dstpal);
4317
4318 if(!*dst)
4319 {
4320 displayinfo("Error",fmt::format("Error loading image: {}",imagepath));
4321 return 2;
4322 }
4323
4324 if(vp_center)
4325 {
4326 picx=picy=0;
4327 }
4328 else
4329 {
4330 picx=(*dst)->w-zq_screen_w;
4331 picy=(*dst)->h-zq_screen_h;
4332 }
4333
4334 return 0;
4335 }
4336
4337 int32_t saveMapAsImage(ALLEGRO_BITMAP* bitmap)
4338 {
4339 char buf[200];
4340 int32_t num=0;
4341
4342 do
4343 {
4344 snprintf(buf, 200, "%szquest_map%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
4345 buf[199]='\0';
4346 }
4347 while(num<99999 && exists(buf));
4348
4349 if (num >= 99999)
4350 InfoDialog("Error", "Failed to save map image! Max map images (99999) already exist!").show();
4351 else if (!al_save_bitmap(buf, bitmap))
4352 InfoDialog("Error", fmt::format("Failed to save map image\n'{}'.", buf)).show();
4353
4354 return D_O_K;
4355 }
4356
4357 int32_t onViewPic()
4358 {
4359 return launchPicViewer(&pic,picpal,picx,picy,picscale,false);
4360 }
4361
4362 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal, int32_t& px2, int32_t& py2, double& scale, bool isviewingmap, bool skipmenu)
4363 {
4364 restore_mouse();
4365 BITMAP *buf;
4366 bool done=false, redraw=true;
4367
4368 popup_zqdialog_start();
4369
4370 // Always call load_the_map() when viewing the map.
4371 if((!*pictoview || isviewingmap) && (isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)))
4372 {
4373 zc_set_palette(RAMpal);
4374 mapview_close();
4375 popup_zqdialog_end();
4376 return D_O_K;
4377 }
4378
4379 MapViewRTI* rti_map_view = mapview_get_rti();
4380
4381 zq_freeze_all_rti();
4382 if (isviewingmap)
4383 rti_map_view->freeze = false;
4384 else
4385 get_screen_rti()->freeze = false;
4386
4387 get_bw(pal,pblack,pwhite);
4388
4389 int32_t oldfgcolor = gui_fg_color;
4390 int32_t oldbgcolor = gui_bg_color;
4391
4392 buf = create_bitmap_ex(8,zq_screen_w,zq_screen_h);
4393
4394 if(!buf)
4395 {
4396 displayinfo("Error","Error creating temp bitmap");
4397 mapview_close();
4398 popup_zqdialog_end();
4399 return D_O_K;
4400 }
4401
4402 static LegacyBitmapRTI viewer_overlay_rti("viewer_overlay");
4403 viewer_overlay_rti.set_size(buf->w, buf->h);
4404 viewer_overlay_rti.a4_bitmap = buf;
4405 viewer_overlay_rti.transparency_index = 15;
4406 viewer_overlay_rti.freeze = false;
4407 get_root_rti()->add_child(&viewer_overlay_rti);
4408
4409 zc_set_palette(pal);
4410
4411 if(isviewingmap)
4412 {
4413 set_center_root_rti(false);
4414
4415 int sw = rti_map_view->width / 16;
4416 int sh = rti_map_view->height / 8;
4417 int screen = Map.getCurrScr();
4418 if (screen >= 0x00 && screen <= 0x7F)
4419 {
4420 auto root_transform = get_root_rti()->get_transform();
4421 int dw = al_get_display_width(all_get_display()) / root_transform.xscale;
4422 int dh = al_get_display_height(all_get_display()) / root_transform.yscale;
4423 mapx = (-(screen % 16) * sw - sw/2 + dw/2);
4424 mapy = (-(screen / 16) * sh - sh/2 + dh/2);
4425 }
4426 }
4427
4428 const double MIN_SCALE = 0.1;
4429 const double MAX_SCALE = 5.0;
4430 auto mouse_x = gui_mouse_x();
4431 auto mouse_y = gui_mouse_y();
4432 int mouse_off_x = 0, mouse_off_y = 0;
4433 double old_scale = scale;
4434 bool mouse_down = false;
4435
4436 do
4437 {
4438 HANDLE_CLOSE_ZQDLG();
4439 if(exiting_program) break;
4440 int w, h;
4441 if (isviewingmap)
4442 {
4443 w = rti_map_view->width;
4444 h = rti_map_view->height;
4445 }
4446 else
4447 {
4448 w = (*pictoview)->w;
4449 h = (*pictoview)->h;
4450 }
4451
4452 if (isviewingmap)
4453 {
4454 auto root_transform = get_root_rti()->get_transform();
4455 int dw = al_get_display_width(all_get_display()) / root_transform.xscale;
4456 int dh = al_get_display_height(all_get_display()) / root_transform.yscale;
4457 mapx = std::max(mapx, (int)(-w*scale + dw));
4458 mapy = std::max(mapy, (int)(-h*scale + dh));
4459 mapx = std::min(mapx, 0);
4460 mapy = std::min(mapy, 0);
4461 rti_map_view->set_transform({mapx, mapy, (float)scale, (float)scale});
4462 }
4463
4464 if(redraw)
4465 {
4466 clear_to_color(buf,15);
4467
4468 if (!isviewingmap)
4469 stretch_blit(*pictoview, buf, 0, 0, w, h,
4470 int32_t(zq_screen_w + (px2 - w) * scale) / 2, int32_t(zq_screen_h + (py2 - h) * scale) / 2,
4471 int32_t(w * scale), int32_t(h * scale));
4472
4473 if(vp_showpal)
4474 for(int32_t i=0; i<256; i++)
4475 rectfill(buf,((i&15)<<2)+zq_screen_w-64,((i>>4)<<2)+zq_screen_h-64,((i&15)<<2)+zq_screen_w-64+3,((i>>4)<<2)+zq_screen_h-64+3,i);
4476
4477 if(vp_showsize)
4478 {
4479 textprintf_ex(buf,font,0,zq_screen_h-8,pwhite,pblack,"%dx%d %.2f%%",w,h,scale*100.0);
4480 }
4481
4482 if (!isviewingmap)
4483 blit(buf,screen,0,0,0,0,zq_screen_w,zq_screen_h);
4484 redraw=false;
4485 }
4486
4487 custom_vsync();
4488
4489 int32_t step = 16;
4490 double scale_step = 0.95;
4491 double scale_bigstep = 2.0;
4492
4493 if(scale < 1.0)
4494 step = int32_t(4.0/ scale);
4495
4496 bool shift = (key[KEY_LSHIFT] || key[KEY_RSHIFT]);
4497 bool ctrl = CHECK_CTRL_CMD;
4498 if (shift)
4499 step <<= 2;
4500 if (ctrl)
4501 step >>= 1;
4502 if (shift && ctrl)
4503 {
4504 scale_step = 0.90;
4505 scale_bigstep = 4.0;
4506 }
4507 else if (shift)
4508 {
4509 scale_step = 0.80;
4510 scale_bigstep = 3.0;
4511 }
4512 else if(ctrl)
4513 {
4514 scale_step = 0.975;
4515 scale_bigstep = 1.5;
4516 }
4517
4518 if(key[KEY_UP])
4519 {
4520 py2+=step;
4521 redraw=true;
4522 }
4523
4524 if(key[KEY_DOWN])
4525 {
4526 py2-=step;
4527 redraw=true;
4528 }
4529
4530 if(key[KEY_LEFT])
4531 {
4532 px2+=step;
4533 redraw=true;
4534 }
4535
4536 if(key[KEY_RIGHT])
4537 {
4538 px2-=step;
4539 redraw=true;
4540 }
4541
4542 if (bool mouse_down_now = (gui_mouse_b() & 1); mouse_down_now != mouse_down)
4543 {
4544 mouse_down = mouse_down_now;
4545 if (mouse_down)
4546 {
4547 mouse_x = gui_mouse_x();
4548 mouse_y = gui_mouse_y();
4549 mouse_off_x = px2;
4550 mouse_off_y = py2;
4551 }
4552 }
4553
4554 if (mouse_down)
4555 {
4556 if (abs(old_scale - scale) > 0.01)
4557 {
4558 mouse_x = gui_mouse_x();
4559 mouse_y = gui_mouse_y();
4560 mouse_off_x = px2;
4561 mouse_off_y = py2;
4562 old_scale = scale;
4563 }
4564 px2 = mouse_off_x + (gui_mouse_x() - mouse_x);
4565 py2 = mouse_off_y + (gui_mouse_y() - mouse_y);
4566 }
4567
4568 if (mouse_z)
4569 {
4570 double new_scale = scale;
4571 for (int q = 0; q < mouse_z; ++q)
4572 new_scale /= scale_step;
4573 for (int q = 0; q > mouse_z; --q)
4574 new_scale *= scale_step;
4575 position_mouse_z(0);
4576
4577 auto mx = (gui_mouse_x() - px2) / scale;
4578 auto my = (gui_mouse_y() - py2) / scale;
4579 scale = vbound(new_scale, MAX_SCALE, MIN_SCALE);
4580
4581 px2 = gui_mouse_x() - (mx * scale);
4582 py2 = gui_mouse_y() - (my * scale);
4583 }
4584
4585 if(keypressed() && !redraw)
4586 switch(readkey()>>8)
4587 {
4588 case KEY_PGUP:
4589 scale *= scale_step;
4590
4591 if(scale<MIN_SCALE) scale = MIN_SCALE;
4592
4593 redraw=true;
4594 break;
4595
4596 case KEY_PGDN:
4597 scale /= scale_step;
4598
4599 if(scale>MAX_SCALE) scale = MAX_SCALE;
4600
4601 redraw = true;
4602 break;
4603
4604 case KEY_HOME:
4605 scale /= scale_bigstep;
4606
4607 if(scale<MIN_SCALE) scale = MIN_SCALE;
4608
4609 redraw = true;
4610 break;
4611
4612 case KEY_END:
4613 scale *= scale_bigstep;
4614
4615 if(scale>MAX_SCALE) scale = MAX_SCALE;
4616
4617 redraw = true;
4618 break;
4619
4620 case KEY_TILDE:
4621 scale = 0.5;
4622 redraw = true;
4623 break;
4624
4625 case KEY_Z:
4626 px2 = w-zq_screen_w;
4627 py2 = h-zq_screen_h;
4628 vp_center = false;
4629 redraw = true;
4630 break;
4631
4632 case KEY_1:
4633 scale = 1.0;
4634 redraw = true;
4635 break;
4636
4637 case KEY_2:
4638 scale = 2.0;
4639 redraw = true;
4640 break;
4641
4642 case KEY_3:
4643 scale = 3.0;
4644 redraw = true;
4645 break;
4646
4647 case KEY_4:
4648 scale = 4.0;
4649 redraw = true;
4650 break;
4651
4652 case KEY_5:
4653 scale = 5.0;
4654 redraw = true;
4655 break;
4656
4657 case KEY_C:
4658 px2 = py2 = 0;
4659 redraw = vp_center = true;
4660 break;
4661
4662 case KEY_S:
4663 vp_showsize = !vp_showsize;
4664 redraw = true;
4665 break;
4666
4667 case KEY_D:
4668 vp_showpal = !vp_showpal;
4669 redraw = true;
4670 break;
4671
4672 case KEY_P:
4673 if(isviewingmap) break;
4674
4675 case KEY_ESC:
4676 done = true;
4677 break;
4678
4679 case KEY_SPACE:
4680 mapview_close();
4681 if(isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)==2)
4682 {
4683 done = true;
4684 }
4685 else
4686 {
4687 redraw = true;
4688 gui_bg_color = pblack;
4689 gui_fg_color = pwhite;
4690 scale = 1.0;
4691 zc_set_palette(pal);
4692 }
4693
4694 get_bw(pal,pblack,pwhite);
4695 break;
4696 }
4697 }
4698 while(!done);
4699
4700 destroy_bitmap(buf);
4701 zc_set_palette(RAMpal);
4702 gui_fg_color = oldfgcolor;
4703 gui_bg_color = oldbgcolor;
4704
4705 position_mouse_z(0);
4706 viewer_overlay_rti.remove();
4707 set_center_root_rti(true);
4708 mapview_close();
4709 popup_zqdialog_end();
4710 return D_O_K;
4711 }
4712
4713 static DIALOG loadmap_dlg[] =
4714 {
4715 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
4716 { jwin_win_proc, 0, 0, 225, 143, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Map", NULL, NULL },
4717 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4718 { jwin_text_proc, 32, 26, 96, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Resolution", NULL, NULL },
4719 // 3
4720 { jwin_radio_proc, 16, 36, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/4 - 1024x352", NULL, NULL },
4721 { jwin_radio_proc, 16, 46, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/2 - 2048x704", NULL, NULL },
4722 { jwin_radio_proc, 16, 56, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full - 4096x1408", NULL, NULL },
4723 { jwin_text_proc, 144, 26, 97, 9, vc(11), vc(1), 0, 0, 0, 0, (void *) "Options", NULL, NULL },
4724 // 7
4725 { jwin_check_proc, 144, 36, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Solidity", NULL, NULL },
4726 { jwin_check_proc, 144, 46, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Flags", NULL, NULL },
4727 { jwin_check_proc, 144, 56, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Dark", NULL, NULL },
4728 { jwin_check_proc, 144, 66, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Items", NULL, NULL },
4729 // 11
4730 { jwin_button_proc, 42, 110, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4731 { jwin_button_proc, 122, 110, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4732 { jwin_check_proc, 16, 88, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Save to Image", NULL, NULL },
4733 // 14
4734 { jwin_radio_proc, 16, 66, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"2x - 8192x2816", NULL, NULL },
4735 { jwin_radio_proc, 16, 76, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"4x - 16384x5632", NULL, NULL },
4736 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4737 };
4738
4739 int32_t load_the_map(bool skipmenu)
4740 {
4741 static int32_t res = 0;
4742 static int32_t flags = cDEBUG;
4743
4744 loadmap_dlg[0].dp2 = get_zc_font(font_lfont);
4745 loadmap_dlg[3].flags = (res==2) ? D_SELECTED : 0;
4746 loadmap_dlg[4].flags = (res==1) ? D_SELECTED : 0;
4747 loadmap_dlg[5].flags = (res==0) ? D_SELECTED : 0;
4748 loadmap_dlg[7].flags = (flags&cWALK) ? D_SELECTED : 0;
4749 loadmap_dlg[8].flags = (flags&cFLAGS) ? D_SELECTED : 0;
4750 loadmap_dlg[9].flags = (flags&cNODARK) ? 0 : D_SELECTED;
4751 loadmap_dlg[10].flags = (flags&cNOITEM) ? 0 : D_SELECTED;
4752 loadmap_dlg[13].flags = 0;
4753 loadmap_dlg[14].flags = (res==3) ? D_SELECTED : 0;
4754 loadmap_dlg[15].flags = (res==4) ? D_SELECTED : 0;
4755
4756 if(!skipmenu)
4757 {
4758 large_dialog(loadmap_dlg);
4759
4760 if (do_zqdialog(loadmap_dlg, 11, true) != 11)
4761 {
4762 return 1;
4763 }
4764
4765 flags = cDEBUG;
4766
4767 if(loadmap_dlg[3].flags&D_SELECTED) res=2;
4768
4769 if(loadmap_dlg[4].flags&D_SELECTED) res=1;
4770
4771 if(loadmap_dlg[5].flags&D_SELECTED) res=0;
4772
4773 if(loadmap_dlg[7].flags&D_SELECTED) flags|=cWALK;
4774
4775 if(loadmap_dlg[8].flags&D_SELECTED) flags|=cFLAGS;
4776
4777 if(!(loadmap_dlg[9].flags&D_SELECTED)) flags|=cNODARK;
4778
4779 if(!(loadmap_dlg[10].flags&D_SELECTED)) flags|=cNOITEM;
4780
4781 if(loadmap_dlg[14].flags&D_SELECTED) res=3;
4782
4783 if(loadmap_dlg[15].flags&D_SELECTED) res=4;
4784 }
4785
4786 int32_t bw = (256*16)>>res;
4787 int32_t bh = (176*8)>>res;
4788 int32_t sw = 256>>res;
4789 int32_t sh = 176>>res;
4790 if(res>2)
4791 {
4792 bw = (256*16)<<(res-2);
4793 bh = (176*8)<<(res-2);
4794 sw = 256<<(res-2);
4795 sh = 176<<(res-2);
4796 }
4797
4798 mapview_open(flags, sw, sh, bw, bh);
4799
4800 vp_showpal = false;
4801 get_bw(picpal,pblack,pwhite);
4802 mapx = mapy = 0;
4803 mapscale = 1;
4804 imagepath[0] = 0;
4805
4806 if(loadmap_dlg[13].flags & D_SELECTED) saveMapAsImage(mapview_get_rti()->bitmap);
4807
4808 memcpy(mappal,RAMpal,sizeof(RAMpal));
4809
4810 return 0;
4811 }
4812
4813 int32_t onViewMap()
4814 {
4815 return onViewMapEx(false);
4816 }
4817 int32_t onViewMapEx(bool skipmenu)
4818 {
4819 int32_t temp_aligns=ShowMisalignments;
4820 ShowMisalignments=0;
4821 launchPicViewer(&bmap,mappal,mapx, mapy, mapscale,true,skipmenu);
4822 ShowMisalignments=temp_aligns;
4823 return D_O_K;
4824 }
4825
4826 static const char *mazedirstr[4] = {"North","South","West","East"};
4827 char _pathstr[40]="North,North,North,North";
4828
4829 char *pathstr(byte path[])
4830 {
4831 sprintf(_pathstr,"%s,%s,%s,%s",mazedirstr[path[0]],mazedirstr[path[1]],
4832 mazedirstr[path[2]],mazedirstr[path[3]]);
4833 return _pathstr;
4834 }
4835
4836 char _ticksstr[32]="99.99 seconds";
4837
4838 char *ticksstr(int32_t tics)
4839 {
4840 int32_t mins=tics/(60*60);
4841 tics=tics-(mins*60*60);
4842 int32_t secs=tics/60;
4843 tics=tics-(secs*60);
4844 tics=tics*100/60;
4845
4846 if(mins>0)
4847 {
4848 sprintf(_ticksstr,"%d:%02d.%02d",mins, secs, tics);
4849 }
4850 else
4851 {
4852 sprintf(_ticksstr,"%d.%02d seconds",secs, tics);
4853 }
4854
4855 return _ticksstr;
4856 }
4857
4858 ZC_FORMAT_PRINTF(7, 8)
4859 void textprintf_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
4860 {
4861 char buf[512];
4862 va_list ap;
4863 ASSERT(bmp);
4864 ASSERT(f);
4865 ASSERT(format);
4866
4867 va_start(ap, format);
4868 vsnprintf(buf, sizeof(buf), format, ap);
4869 va_end(ap);
4870
4871
4872 textout_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
4873
4874 textout_ex(bmp, f, buf, x, y, color_sh, -1);
4875 }
4876
4877 ZC_FORMAT_PRINTF(7, 8)
4878 void textprintf_centre_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
4879 {
4880 char buf[512];
4881 va_list ap;
4882 ASSERT(bmp);
4883 ASSERT(f);
4884 ASSERT(format);
4885
4886 va_start(ap, format);
4887 vsnprintf(buf, sizeof(buf), format, ap);
4888 va_end(ap);
4889
4890 textout_centre_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
4891 textout_centre_ex(bmp, f, buf, x, y, color_sh, -1);
4892 }
4893
4894 void draw_sqr_frame(size_and_pos const& sqr)
4895 {
4896 jwin_draw_frame(screen,sqr.x,sqr.y,sqr.tw(),sqr.th(),FR_DEEP);
4897 }
4898 void draw_sqr_icon(size_and_pos const& sqr, BITMAP* icon)
4899 {
4900 stretch_blit(icon, screen, 0, 0, 16, 16, sqr.x+2, sqr.y+2, sqr.tw()-4, sqr.th()-4);
4901 }
4902 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num)
4903 {
4904 if(center)
4905 textprintf_centre_ex(screen,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
4906 else
4907 textprintf_ex(screen,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
4908 }
4909 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num1, int num2)
4910 {
4911 if(center)
4912 {
4913 textprintf_centre_ex(screen,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
4914 textprintf_centre_ex(screen,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
4915 }
4916 else
4917 {
4918 textprintf_ex(screen,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
4919 textprintf_ex(screen,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
4920 }
4921 }
4922 void draw_sqr_btn(size_and_pos const& sqr, const char* txt, int flags, FONT* f = nullptr)
4923 {
4924 if(sqr.x < 0) return;
4925 FONT* tfont = font;
4926 if(f)
4927 font = f;
4928 draw_text_button(screen, sqr.x, sqr.y, sqr.tw(), sqr.th(), txt, 0, 0, flags, true);
4929 font = tfont;
4930 }
4931 void draw_sqr_btn(size_and_pos const& sqr, int icon, int flags, FONT* f = nullptr)
4932 {
4933 if(sqr.x < 0) return;
4934 FONT* tfont = font;
4935 if(f)
4936 font = f;
4937 draw_icon_button(screen, sqr.x, sqr.y, sqr.tw(), sqr.th(), icon, 0, 0, flags, true);
4938 font = tfont;
4939 }
4940
4941 void drawpanel()
4942 {
4943 mapscr *scr=Map.CurrScr();
4944 int32_t NextCombo = combobuf[Combo].nextcombo;
4945 int32_t NextCSet = combobuf[Combo].nextcset;
4946 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
4947 {
4948 NextCombo = scr->undercombo;
4949 NextCSet = scr->undercset;
4950 }
4951 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
4952 NextCSet = CSet;
4953
4954 FONT* tfont = font;
4955 if(prv_mode)
4956 {
4957 jwin_draw_frame(screen,0,preview_panel.y,preview_panel.x+preview_panel.w, preview_panel.h, FR_WIN);
4958 rectfill(screen,preview_panel.x,preview_panel.y+2,preview_panel.x+preview_panel.w-3,preview_panel.y+preview_panel.h-3,jwin_pal[jcBOX]);
4959 }
4960 else
4961 {
4962 auto& sqr = main_panel;
4963 rectfill(screen,sqr.x,sqr.y,sqr.x+sqr.w-1,sqr.y+sqr.h-1, jwin_pal[jcBOX]);
4964 refresh(rSCRMAP);
4965 jwin_draw_frame(screen,sqr.x,sqr.y,sqr.w,sqr.h, FR_WIN);
4966
4967 font = get_custom_font(CFONT_GUI);
4968 draw_sqr_btn(squarepanel_swap_btn, "SWP", 0);
4969 if(compact_square_panels)
4970 {
4971 textprintf_centre_ex(screen,font,squarepanel_up_btn.cx(),squarepanel_up_btn.y-text_height(font)-2,jwin_pal[jcBOXFG],-1,"%d",compact_active_panel);
4972 draw_sqr_btn(squarepanel_up_btn, BTNICON_ARROW_UP, 0);
4973 draw_sqr_btn(squarepanel_down_btn, BTNICON_ARROW_DOWN, 0);
4974 }
4975 font = tfont;
4976
4977 FONT* sqr_text_font = (is_compact && compact_square_panels) ? get_custom_font(CFONT_GUI) : font;
4978 //Item:
4979 if(itemsqr_pos.x > -1)
4980 {
4981 draw_sqr_frame(itemsqr_pos);
4982 if(scr->hasitem)
4983 {
4984 rectfill(screen,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsqr_pos.x+itemsqr_pos.tw()-3,itemsqr_pos.y+itemsqr_pos.th()-3,0);
4985 overtile16_scale(screen, itemsbuf[scr->item].tile,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsbuf[scr->item].csets&15,0,itemsqr_pos.tw()-4,itemsqr_pos.th()-4);
4986 }
4987 else draw_sqr_icon(itemsqr_pos, icon_bmp[0][coord_frame]);
4988 draw_sqr_nums(itemsqr_pos, sqr_text_font, panel_align == 1, scr->itemx, scr->itemy);
4989 }
4990 //Flag:
4991 if(flagsqr_pos.x > -1)
4992 {
4993 draw_sqr_frame(flagsqr_pos);
4994 draw_sqr_icon(flagsqr_pos,flag_bmp[Flag%16][coord_frame]);
4995 draw_sqr_nums(flagsqr_pos, sqr_text_font, panel_align == 1, Flag);
4996 }
4997
4998 //Stairs:
4999 if(stairsqr_pos.x > -1)
5000 {
5001 draw_sqr_frame(stairsqr_pos);
5002 draw_sqr_icon(stairsqr_pos,icon_bmp[1][coord_frame]);
5003 draw_sqr_nums(stairsqr_pos, sqr_text_font, panel_align == 1, scr->stairx, scr->stairy);
5004 }
5005
5006 //Green arrival square:
5007 bool disabled_arrival = get_qr(qr_NOARRIVALPOINT);
5008 if(warparrival_pos.x > -1)
5009 {
5010 draw_sqr_frame(warparrival_pos);
5011 BITMAP* icon = icon_bmp[2][coord_frame];
5012 if(disabled_arrival)
5013 {
5014 icon = create_bitmap_ex(8,16,16);
5015 blit(icon_bmp[2][0], icon, 0, 0, 0, 0, 16, 16);
5016 replColor(icon, 0xE7, 0xEA, 0xEA, false);
5017 replColor(icon, 0xE8, 0xE2, 0xE2, false);
5018 }
5019
5020 draw_sqr_icon(warparrival_pos, icon);
5021 draw_sqr_nums(warparrival_pos, sqr_text_font, panel_align == 1, scr->warparrivalx, scr->warparrivaly);
5022
5023 if(disabled_arrival)
5024 destroy_bitmap(icon);
5025 }
5026
5027 //Blue return squares:
5028 for(int32_t i=0; i<4; i++)
5029 {
5030 if(warpret_pos[i].x < 0) continue;
5031 draw_sqr_frame(warpret_pos[i]);
5032 draw_sqr_icon(warpret_pos[i], icon_bmp[ICON_BMP_RETURN_A+i][coord_frame]);
5033 draw_sqr_nums(warpret_pos[i], sqr_text_font, panel_align == 1, scr->warpreturnx[i], scr->warpreturny[i]);
5034 }
5035
5036 // Enemies
5037 auto& ep = enemy_prev_pos;
5038 if(ep.x > -1)
5039 {
5040 if(ep.fw > -1)
5041 {
5042 rectfill(screen, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5043 rectfill(screen, ep.x+ep.fw, ep.y+ep.fh, ep.x+ep.tw()-1, ep.y+ep.th()-1, jwin_pal[jcBOX]);
5044 jwin_draw_frag_frame(screen, ep.x, ep.y, ep.tw(), ep.th(), ep.fw, ep.fh, FR_DEEP);
5045 }
5046 else
5047 {
5048 rectfill(screen, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5049 draw_sqr_frame(ep);
5050 }
5051 for(int32_t i=0; i< 10 && Map.CurrScr()->enemy[i]!=0; i++)
5052 {
5053 int32_t id = Map.CurrScr()->enemy[i];
5054 int32_t tile = get_qr(qr_NEWENEMYTILES) ? guysbuf[id].e_tile : guysbuf[id].tile;
5055 int32_t cset = guysbuf[id].cset;
5056 auto& sqr = ep.subsquare(i);
5057 if(tile)
5058 overtile16_scale(screen, tile+efrontfacingtile(id),sqr.x,sqr.y,cset,0,sqr.tw(),sqr.th());
5059 }
5060 }
5061 }
5062 font = tfont;
5063 }
5064
5065 void show_screen_error(const char *str, int32_t i, int32_t c)
5066 {
5067 rectfill(screen, screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),screrrorpos.x,screrrorpos.y-((i-1)*16)-4,vc(0));
5068 textout_shadowed_ex(screen,get_zc_font(font_lfont_l), str,screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),c,vc(0),-1);
5069 }
5070
5071 void tile_warp_notification(int32_t which, char *buf)
5072 {
5073 char letter = 'A'+which;
5074
5075 switch(Map.CurrScr()->tilewarptype[which])
5076 {
5077 case wtCAVE:
5078 sprintf(buf,"Tile Warp %c: Cave/Item Cellar",letter);
5079 break;
5080
5081 default:
5082 {
5083 char buf2[30];
5084
5085 if(strlen(DMaps[Map.CurrScr()->tilewarpdmap[which]].name)==0)
5086 {
5087 sprintf(buf2,"%d",Map.CurrScr()->tilewarpdmap[which]);
5088 }
5089 else
5090 sprintf(buf2,"%d-%s",Map.CurrScr()->tilewarpdmap[which],DMaps[Map.CurrScr()->tilewarpdmap[which]].name);
5091
5092 sprintf(buf,"Tile Warp %c: %s, %02X", letter, buf2, Map.CurrScr()->tilewarpscr[which]);
5093 break;
5094 }
5095
5096 case wtNOWARP:
5097 sprintf(buf,"Tile Warp %c: Cancel Warp", letter);
5098 break;
5099 }
5100 }
5101
5102 void side_warp_notification(int32_t which, int32_t dir, char *buf)
5103 {
5104 char letter = 'A'+which;
5105 char buf3[16];
5106
5107 if(dir==0 && Map.CurrScr()->timedwarptics)
5108 sprintf(buf3,"%s, Timed",mazedirstr[dir]);
5109 else if(dir==4)
5110 sprintf(buf3,"Timed");
5111 else
5112 strcpy(buf3, mazedirstr[dir]);
5113
5114 switch(Map.CurrScr()->sidewarptype[which])
5115 {
5116 case wtCAVE:
5117 sprintf(buf,"Side Warp %c (%s): Cave/Item Cellar",letter, buf3);
5118 break;
5119
5120 default:
5121 {
5122 // Destination DMap name
5123 if(strlen(DMaps[Map.CurrScr()->sidewarpdmap[which]].name)==0)
5124 {
5125 sprintf(buf,"Side Warp %c (%s): %d, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which], Map.CurrScr()->sidewarpscr[which]);
5126 }
5127 else
5128 sprintf(buf,"Side Warp %c (%s): %d-%s, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which],DMaps[Map.CurrScr()->sidewarpdmap[which]].name, Map.CurrScr()->sidewarpscr[which]);
5129
5130 break;
5131 }
5132
5133 case wtNOWARP:
5134 sprintf(buf,"Side Warp %c (%s): Cancel Warp", letter, buf3);
5135 break;
5136 }
5137 }
5138
5139 static bool arrowcursor = true; // Used by combo aliases and Combo Brush cursors. -L
5140
5141 void xout(BITMAP* dest, int x, int y, int x2, int y2, int c, int bgc = -1)
5142 {
5143 //BG Fill
5144 if(bgc > -1)
5145 rectfill(dest, x, y, x2, y2, bgc);
5146 ++x; ++y; --x2; --y2;
5147 //Border
5148 safe_rect(dest, x, y, x2, y2, c);
5149 //line(dest, x, y, x2, y, c);
5150 //line(dest, x, y, x, y2, c);
5151 //X
5152 line(dest, x, y, x2, y2, c);
5153 line(dest, x, y2, x2, y, c);
5154 }
5155
5156 void put_autocombo_engravings(BITMAP* dest, combo_auto const& ca, bool selected, int32_t x, int32_t y, int32_t scale)
5157 {
5158 if (!ca.valid())
5159 {
5160 if (ca.getDisplay() > 0)
5161 put_engraving(dest, x, y, 15, scale);
5162 }
5163 else
5164 {
5165 if (ca.getType() == AUTOCOMBO_Z4 || ca.getType() == AUTOCOMBO_DOR)
5166 {
5167 byte hei = vbound(ca.getArg() + 1, 1, 9);
5168 if (selected)
5169 hei = vbound(cauto_height, 1, 9);
5170 put_engraving(dest, x, y, 15 - hei, scale);
5171 }
5172 }
5173 }
5174
5175 static void draw_screenunit_map_screen2(VisibleScreen visible_screen)
5176 {
5177 BITMAP* screen_bitmap = screen;
5178
5179 int num_screens_to_draw = Map.getViewSize();
5180 int screen = visible_screen.screen;
5181 int xoff = visible_screen.xoff;
5182 int yoff = visible_screen.yoff;
5183
5184 mapscr* scr = visible_screen.scr;
5185 if (!layers_valid(scr))
5186 fix_layers(scr, true);
5187
5188 clear_to_color(mapscreenbmp, 0);
5189
5190 int view_scr_x = Map.getViewScr() % 16;
5191 int view_scr_y = Map.getViewScr() / 16;
5192 int scr_x = screen % 16;
5193 int scr_y = screen / 16;
5194 int edge_xoff = 0, edge_yoff = 0;
5195 if(showedges)
5196 {
5197 if (scr_x == view_scr_x)
5198 edge_xoff = 16;
5199 else
5200 xoff -= 16;
5201
5202 if (scr_y == view_scr_y)
5203 edge_yoff = 16;
5204 else
5205 yoff -= 16;
5206 }
5207
5208 // TODO: should be better to move this out of draw_screenunit_map_screen.
5209 if (showedges && screen < 128)
5210 {
5211 bool peek_above = scr_y == view_scr_y;
5212 bool peek_below = scr_y == view_scr_y + num_screens_to_draw - 1;
5213 bool peek_left = scr_x == view_scr_x;
5214 bool peek_right = scr_x == view_scr_x + num_screens_to_draw - 1;
5215
5216 int right_col = 272 - (num_screens_to_draw > 1 ? 16 : 0);
5217 int bottom_row = 192 - (num_screens_to_draw > 1 ? 16 : 0);
5218
5219 //not the first row of screens
5220 if (peek_above)
5221 {
5222 if(screen>15 && !NoScreenPreview)
5223 {
5224 Map.drawrow(mapscreenbmp, edge_xoff, 0, Flags, 160, -1, screen-16);
5225 }
5226 else
5227 {
5228 Map.drawstaticrow(mapscreenbmp, edge_xoff, 0);
5229 }
5230 }
5231
5232 //not the last row of screens
5233 if (peek_below)
5234 {
5235 if(screen + 16 < 0x80 && !NoScreenPreview)
5236 {
5237 Map.drawrow(mapscreenbmp, edge_xoff, bottom_row, Flags, 0, -1, screen+16);
5238 }
5239 else
5240 {
5241 Map.drawstaticrow(mapscreenbmp, edge_xoff, bottom_row);
5242 }
5243 }
5244
5245 //not the first column of screens
5246 if (peek_left)
5247 {
5248 if(screen&0x0F && !NoScreenPreview)
5249 {
5250 Map.drawcolumn(mapscreenbmp, 0, edge_yoff, Flags, 15, -1, screen-1);
5251 }
5252 else
5253 {
5254 Map.drawstaticcolumn(mapscreenbmp, 0, edge_yoff);
5255 }
5256 }
5257
5258 //not the last column of screens
5259 if (peek_right)
5260 {
5261 if((screen&0x0F)<15 && !NoScreenPreview)
5262 {
5263 Map.drawcolumn(mapscreenbmp, right_col, edge_yoff, Flags, 0, -1, screen+1);
5264 }
5265 else
5266 {
5267 Map.drawstaticcolumn(mapscreenbmp, right_col, edge_yoff);
5268 }
5269 }
5270
5271 //not the first row or first column of screens
5272 if (peek_above && peek_left)
5273 {
5274 if((screen>15)&&(screen&0x0F) && !NoScreenPreview)
5275 {
5276 Map.drawblock(mapscreenbmp, 0, 0, Flags, 175, -1, screen-17);
5277 }
5278 else
5279 {
5280 Map.drawstaticblock(mapscreenbmp, 0, 0);
5281 }
5282 }
5283
5284 //not the first row or last column of screens
5285 if (peek_above && peek_right)
5286 {
5287 if((screen>15)&&((screen&0x0F)<15) && !NoScreenPreview)
5288 {
5289 Map.drawblock(mapscreenbmp, right_col, 0, Flags, 160, -1, screen-15);
5290 }
5291 else
5292 {
5293 Map.drawstaticblock(mapscreenbmp, right_col, 0);
5294 }
5295 }
5296
5297 //not the last row or first column of screens
5298 if (peek_below && peek_left)
5299 {
5300 if((screen<112)&&(screen&0x0F) && !NoScreenPreview)
5301 {
5302 Map.drawblock(mapscreenbmp, 0, bottom_row, Flags, 15, -1, screen+15);
5303 }
5304 else
5305 {
5306 Map.drawstaticblock(mapscreenbmp, 0, bottom_row);
5307 }
5308 }
5309
5310 //not the last row or last column of screens
5311 if (peek_below && peek_right)
5312 {
5313 if((screen<112)&&((screen&0x0F)<15) && !NoScreenPreview)
5314 {
5315 Map.drawblock(mapscreenbmp, right_col, bottom_row, Flags, 0, -1, screen+17);
5316 }
5317 else
5318 {
5319 Map.drawstaticblock(mapscreenbmp, right_col, bottom_row);
5320 }
5321 }
5322 }
5323
5324 if (ShowSquares && Map.getViewSize() < 4)
5325 {
5326 if(scr->stairx || scr->stairy)
5327 {
5328 int32_t x1 = scr->stairx+edge_xoff;
5329 int32_t y1 = scr->stairy+edge_yoff;
5330 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(14));
5331 }
5332
5333 if(scr->warparrivalx || scr->warparrivaly)
5334 {
5335 int32_t x1 = scr->warparrivalx +edge_xoff;
5336 int32_t y1 = scr->warparrivaly +edge_yoff;
5337 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(10));
5338 }
5339
5340 for(int32_t i=0; i<4; i++) if(scr->warpreturnx[i] || scr->warpreturny[i])
5341 {
5342 int32_t x1 = scr->warpreturnx[i]+edge_xoff;
5343 int32_t y1 = scr->warpreturny[i]+edge_yoff;
5344 int32_t clr = vc(9);
5345
5346 if(FlashWarpSquare==i)
5347 {
5348 if(!FlashWarpClk)
5349 FlashWarpSquare=-1;
5350 else if(!(--FlashWarpClk%3))
5351 clr = vc(15);
5352 }
5353
5354 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,clr);
5355 }
5356 }
5357
5358 if(ShowFFCs)
5359 {
5360 mapscr* ffscr = prv_mode ? Map.get_prvscr() : scr;
5361 int num_ffcs = ffscr->numFFC();
5362 for(int32_t i=num_ffcs-1; i>=0; i--)
5363 {
5364 ffcdata& ff = ffscr->ffcs[i];
5365 if(ff.data !=0 && (ff.layer >= CurrentLayer || (ff.flags&ffc_overlay)))
5366 {
5367 auto x = ff.x+edge_xoff;
5368 auto y = ff.y+edge_yoff;
5369 safe_rect(mapscreenbmp, x+0, y+0, x+ff.txsz*16-1, y+ff.tysz*16-1, vc(12));
5370 }
5371 }
5372 }
5373
5374 if(num_screens_to_draw == 1 && !(Flags&cDEBUG) && pixeldb==1)
5375 {
5376 for(int32_t j=168; j<176; j++)
5377 {
5378 for(int32_t i=0; i<256; i++)
5379 {
5380 if(((i^j)&1)==0)
5381 {
5382 putpixel(mapscreenbmp,edge_xoff+i,
5383 edge_yoff+j,vc(blackout_color));
5384 }
5385 }
5386 }
5387 }
5388
5389 int w = mapscreenbmp->w * mapscreen_single_scale;
5390 int h = mapscreenbmp->h * mapscreen_single_scale;
5391 stretch_blit(mapscreenbmp, screen_bitmap, 0, 0, mapscreenbmp->w, mapscreenbmp->h, mapscreen_x + xoff, mapscreen_y + yoff, w, h);
5392 }
5393
5394 static void draw_screenunit_map_screen(VisibleScreen visible_screen)
5395 {
5396 BITMAP* screen_bitmap = screen;
5397
5398 if (HighQualityScreenRendering) return draw_screenunit_map_screen2(visible_screen);
5399
5400 int num_screens_to_draw = Map.getViewSize();
5401 int screen = visible_screen.screen;
5402 int xoff = visible_screen.xoff;
5403 int yoff = visible_screen.yoff;
5404
5405 mapscr* scr = visible_screen.scr;
5406 if (!layers_valid(scr))
5407 fix_layers(scr, true);
5408
5409 clear_to_color(mapscreenbmp, jwin_pal[jcBOX]);
5410 if (LayerDitherBG > -1)
5411 {
5412 if (LayerDitherSz > 0)
5413 ditherblit(mapscreenbmp, nullptr, vc(LayerDitherBG), dithChecker, LayerDitherSz);
5414 else
5415 clear_to_color(mapscreenbmp, vc(LayerDitherBG));
5416 }
5417
5418 int view_scr_x = Map.getViewScr() % 16;
5419 int view_scr_y = Map.getViewScr() / 16;
5420 int scr_x = screen % 16;
5421 int scr_y = screen / 16;
5422 int edge_xoff = 0, edge_yoff = 0;
5423 if(showedges)
5424 {
5425 if (scr_x == view_scr_x)
5426 edge_xoff = 16;
5427 else
5428 xoff -= 16;
5429
5430 if (scr_y == view_scr_y)
5431 edge_yoff = 16;
5432 else
5433 yoff -= 16;
5434 }
5435
5436 combotile_add_x = mapscreen_x + xoff;
5437 combotile_add_y = mapscreen_y + yoff;
5438 combotile_mul_x = mapscreen_single_scale;
5439 combotile_mul_y = mapscreen_single_scale;
5440 Map.draw(mapscreenbmp, scr_x == view_scr_x && showedges ? 16 : 0, scr_y == view_scr_y && showedges ? 16 : 0, Flags, Map.getCurrMap(), screen, ActiveLayerHighlight ? CurrentLayer : -1);
5441 combotile_add_x = 0;
5442 combotile_add_y = 0;
5443 combotile_mul_x = 1;
5444 combotile_mul_y = 1;
5445
5446 // TODO: should be better to move this out of draw_screenunit_map_screen.
5447 if (showedges && screen < 128)
5448 {
5449 bool peek_above = scr_y == view_scr_y;
5450 bool peek_below = scr_y == view_scr_y + num_screens_to_draw - 1;
5451 bool peek_left = scr_x == view_scr_x;
5452 bool peek_right = scr_x == view_scr_x + num_screens_to_draw - 1;
5453
5454 int right_col = 272 - (num_screens_to_draw > 1 ? 16 : 0);
5455 int bottom_row = 192 - (num_screens_to_draw > 1 ? 16 : 0);
5456
5457 //not the first row of screens
5458 if (peek_above)
5459 {
5460 if(screen>15 && !NoScreenPreview)
5461 {
5462 Map.drawrow(mapscreenbmp, edge_xoff, 0, Flags, 160, -1, screen-16);
5463 }
5464 else
5465 {
5466 Map.drawstaticrow(mapscreenbmp, edge_xoff, 0);
5467 }
5468 }
5469
5470 //not the last row of screens
5471 if (peek_below)
5472 {
5473 if(screen + 16 < 0x80 && !NoScreenPreview)
5474 {
5475 Map.drawrow(mapscreenbmp, edge_xoff, bottom_row, Flags, 0, -1, screen+16);
5476 }
5477 else
5478 {
5479 Map.drawstaticrow(mapscreenbmp, edge_xoff, bottom_row);
5480 }
5481 }
5482
5483 //not the first column of screens
5484 if (peek_left)
5485 {
5486 if(screen&0x0F && !NoScreenPreview)
5487 {
5488 Map.drawcolumn(mapscreenbmp, 0, edge_yoff, Flags, 15, -1, screen-1);
5489 }
5490 else
5491 {
5492 Map.drawstaticcolumn(mapscreenbmp, 0, edge_yoff);
5493 }
5494 }
5495
5496 //not the last column of screens
5497 if (peek_right)
5498 {
5499 if((screen&0x0F)<15 && !NoScreenPreview)
5500 {
5501 Map.drawcolumn(mapscreenbmp, right_col, edge_yoff, Flags, 0, -1, screen+1);
5502 }
5503 else
5504 {
5505 Map.drawstaticcolumn(mapscreenbmp, right_col, edge_yoff);
5506 }
5507 }
5508
5509 //not the first row or first column of screens
5510 if (peek_above && peek_left)
5511 {
5512 if((screen>15)&&(screen&0x0F) && !NoScreenPreview)
5513 {
5514 Map.drawblock(mapscreenbmp, 0, 0, Flags, 175, -1, screen-17);
5515 }
5516 else
5517 {
5518 Map.drawstaticblock(mapscreenbmp, 0, 0);
5519 }
5520 }
5521
5522 //not the first row or last column of screens
5523 if (peek_above && peek_right)
5524 {
5525 if((screen>15)&&((screen&0x0F)<15) && !NoScreenPreview)
5526 {
5527 Map.drawblock(mapscreenbmp, right_col, 0, Flags, 160, -1, screen-15);
5528 }
5529 else
5530 {
5531 Map.drawstaticblock(mapscreenbmp, right_col, 0);
5532 }
5533 }
5534
5535 //not the last row or first column of screens
5536 if (peek_below && peek_left)
5537 {
5538 if((screen<112)&&(screen&0x0F) && !NoScreenPreview)
5539 {
5540 Map.drawblock(mapscreenbmp, 0, bottom_row, Flags, 15, -1, screen+15);
5541 }
5542 else
5543 {
5544 Map.drawstaticblock(mapscreenbmp, 0, bottom_row);
5545 }
5546 }
5547
5548 //not the last row or last column of screens
5549 if (peek_below && peek_right)
5550 {
5551 if((screen<112)&&((screen&0x0F)<15) && !NoScreenPreview)
5552 {
5553 Map.drawblock(mapscreenbmp, right_col, bottom_row, Flags, 0, -1, screen+17);
5554 }
5555 else
5556 {
5557 Map.drawstaticblock(mapscreenbmp, right_col, bottom_row);
5558 }
5559 }
5560 }
5561
5562 if (ShowSquares && Map.getViewSize() < 4)
5563 {
5564 if(scr->stairx || scr->stairy)
5565 {
5566 int32_t x1 = scr->stairx+edge_xoff;
5567 int32_t y1 = scr->stairy+edge_yoff;
5568 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(14));
5569 }
5570
5571 if(scr->warparrivalx || scr->warparrivaly)
5572 {
5573 int32_t x1 = scr->warparrivalx +edge_xoff;
5574 int32_t y1 = scr->warparrivaly +edge_yoff;
5575 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(10));
5576 }
5577
5578 for(int32_t i=0; i<4; i++) if(scr->warpreturnx[i] || scr->warpreturny[i])
5579 {
5580 int32_t x1 = scr->warpreturnx[i]+edge_xoff;
5581 int32_t y1 = scr->warpreturny[i]+edge_yoff;
5582 int32_t clr = vc(9);
5583
5584 if(FlashWarpSquare==i)
5585 {
5586 if(!FlashWarpClk)
5587 FlashWarpSquare=-1;
5588 else if(!(--FlashWarpClk%3))
5589 clr = vc(15);
5590 }
5591
5592 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,clr);
5593 }
5594 }
5595
5596 if(ShowFFCs)
5597 {
5598 mapscr* ffscr = prv_mode ? Map.get_prvscr() : scr;
5599 int num_ffcs = ffscr->numFFC();
5600 for(int32_t i=num_ffcs-1; i>=0; i--)
5601 {
5602 ffcdata& ff = ffscr->ffcs[i];
5603 if(ff.data !=0 && (ff.layer >= CurrentLayer || (!CurrentLayer && ff.layer < 0) || (ff.flags&ffc_overlay)))
5604 {
5605 auto x = ff.x+edge_xoff;
5606 auto y = ff.y+edge_yoff;
5607 safe_rect(mapscreenbmp, x+0, y+0, x+ff.txsz*16-1, y+ff.tysz*16-1, vc(12));
5608 }
5609 }
5610 }
5611
5612 if(num_screens_to_draw == 1 && !(Flags&cDEBUG) && pixeldb==1)
5613 {
5614 for(int32_t j=168; j<176; j++)
5615 {
5616 for(int32_t i=0; i<256; i++)
5617 {
5618 if(((i^j)&1)==0)
5619 {
5620 putpixel(mapscreenbmp,edge_xoff+i,
5621 edge_yoff+j,vc(blackout_color));
5622 }
5623 }
5624 }
5625 }
5626
5627 int w = mapscreenbmp->w * mapscreen_single_scale;
5628 int h = mapscreenbmp->h * mapscreen_single_scale;
5629 stretch_blit(mapscreenbmp, screen_bitmap, 0, 0, mapscreenbmp->w, mapscreenbmp->h, mapscreen_x + xoff, mapscreen_y + yoff, w, h);
5630 }
5631
5632 static void draw_static_pos(const size_and_pos& sqr)
5633 {
5634 draw_static(screen, sqr.x, sqr.y, sqr.w, sqr.h);
5635 }
5636
5637 void draw_screenunit(int32_t unit, int32_t flags)
5638 {
5639 FONT* tfont = font;
5640 switch(unit)
5641 {
5642 case rSCRMAP:
5643 {
5644 mmap_mark_active();
5645
5646 size_and_pos *mini_sqr = &minimap;
5647 size_and_pos *real_mini_sqr = &real_minimap;
5648
5649 if(zoomed_minimap)
5650 {
5651 mini_sqr = &minimap_zoomed;
5652 real_mini_sqr = &real_minimap_zoomed;
5653 }
5654
5655 auto txt_x = real_mini_sqr->x+2+8*real_mini_sqr->xscale;
5656 auto txt_y = real_mini_sqr->y+2+8*real_mini_sqr->yscale;
5657
5658 rectfill(screen, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->x+mini_sqr->w-1,mini_sqr->y+mini_sqr->h-1,jwin_pal[jcBOX]);
5659 if(zoomed_minimap)
5660 jwin_draw_frame(screen, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->w,mini_sqr->h,FR_WIN);
5661 jwin_draw_minimap_frame(screen,real_mini_sqr->x,real_mini_sqr->y,real_mini_sqr->tw(), real_mini_sqr->th(), real_mini_sqr->xscale, FR_DEEP);
5662
5663 if(Map.getCurrMap()<Map.getMapCount())
5664 {
5665 for(int32_t i=0; i<MAPSCRS; i++)
5666 {
5667 auto& sqr = real_mini_sqr->subsquare(i);
5668
5669 if(Map.Scr(i)->valid&mVALID)
5670 {
5671 // Drawing is handled by mmap_draw.
5672 }
5673 else
5674 {
5675 if (InvalidBG == 2)
5676 {
5677 draw_checkerboard(screen, sqr.x, sqr.y, sqr.w);
5678 }
5679 else if (InvalidBG == 1)
5680 {
5681 draw_static_pos(sqr);
5682 }
5683 else
5684 {
5685 int32_t offs = 2*(sqr.w/9);
5686 draw_x(screen, sqr.x+offs, sqr.y+offs, sqr.x+sqr.w-1-offs, sqr.y+sqr.h-1-offs, vc(15));
5687 }
5688 }
5689 }
5690
5691 int32_t s=Map.getCurrScr();
5692
5693 BITMAP* txtbmp = create_bitmap_ex(8,256,64);
5694 clear_bitmap(txtbmp);
5695 int txtscale = zoomed_minimap ? (is_compact ? 2 : 3) : 1;
5696 font = get_zc_font(font_lfont_l);
5697
5698 int32_t space = text_length(font, "255")+2, spc_s = text_length(font, "S")+2, spc_m = text_length(font, "M")+2;
5699 textprintf_disabled(txtbmp,font,0,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"M");
5700 static int map_shortcut_tooltip_id = ttip_register_id();
5701 ttip_install(map_shortcut_tooltip_id, "Prev map: ,\nNext map: .", txt_x, txt_y, 30, 20, txt_x, txt_y - 60);
5702
5703 textprintf_ex(txtbmp,font,spc_m,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%-3d",Map.getCurrMap()+1);
5704
5705 textprintf_disabled(txtbmp,font,spc_m+space,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"S");
5706 textprintf_ex(txtbmp,font,spc_m+space+spc_s,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"0x%02X (%d)",s, s);
5707 masked_stretch_blit(txtbmp, screen, 0, 0, 256, 64, txt_x, txt_y, 256*txtscale, 64*txtscale);
5708 destroy_bitmap(txtbmp);
5709 }
5710 }
5711 break;
5712 case rMAP:
5713 {
5714 refresh_visible_screens();
5715 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
5716
5717 int num_combos_width = 16 * Map.getViewSize();
5718 int num_combos_height = 11 * Map.getViewSize();
5719
5720 if(CurrentLayer > 0 && !mapscreen_valid_layers[CurrentLayer-1])
5721 CurrentLayer = 0;
5722
5723 if (HighQualityScreenRendering)
5724 {
5725 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
5726 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
5727 int w = 256*mapscreen_screenunit_scale*Map.getViewSize();
5728 int h = 176*mapscreen_screenunit_scale*Map.getViewSize();
5729
5730 MapViewRTI* rti_map_view = mapview_get_rti();
5731 rti_map_view->flags = Flags;
5732 rti_map_view->set_transform({.x = startxint, .y = startyint, .xscale = (float)mapscreen_single_scale, .yscale = (float)mapscreen_single_scale});
5733 rti_map_view->set_size(w, h);
5734 rti_map_view->dirty = true;
5735 rti_map_view->freeze = false;
5736 // TODO: could be improved. This currently makes the transform dirty every frame.
5737 get_root_rti()->add_child_before(rti_map_view, get_screen_rti());
5738 }
5739
5740 // Since the screen renders over the map view when HQR is enabled, the screen rti needs to be transparent.
5741 // But not if HQR is off, that would cause bugs when drawing color 0.
5742 get_screen_rti()->transparency_index = HighQualityScreenRendering ? 0 : -1;
5743
5744 for (auto& vis_screen : visible_screens)
5745 {
5746 draw_screenunit_map_screen(vis_screen);
5747 }
5748
5749 if (showxypos_icon)
5750 {
5751 int x0 = showxypos_x + (showedges?16:0);
5752 int y0 = showxypos_y + (showedges?16:0);
5753 int x1 = x0 + showxypos_w - 1;
5754 int y1 = y0 + showxypos_h - 1;
5755 x0 *= mapscreen_single_scale;
5756 y0 *= mapscreen_single_scale;
5757 x1 *= mapscreen_single_scale;
5758 y1 *= mapscreen_single_scale;
5759 x0 += mapscreen_x;
5760 y0 += mapscreen_y;
5761 x1 += mapscreen_x;
5762 y1 += mapscreen_y;
5763
5764 if (showxypos_color == vc(15))
5765 safe_rect(screen, x0, y0, x1, y1, showxypos_color);
5766 else
5767 rectfill(screen, x0, y0, x1, y1, showxypos_color);
5768 }
5769
5770 if(showxypos_cursor_icon)
5771 {
5772 int x0 = showxypos_cursor_x + (showedges?16:0);
5773 int y0 = showxypos_cursor_y + (showedges?16:0);
5774 int x1 = x0 + showxypos_w - 1;
5775 int y1 = y0 + showxypos_h - 1;
5776 x0 *= mapscreen_single_scale;
5777 y0 *= mapscreen_single_scale;
5778 x1 *= mapscreen_single_scale;
5779 y1 *= mapscreen_single_scale;
5780 x0 += mapscreen_x;
5781 y0 += mapscreen_y;
5782 x1 += mapscreen_x;
5783 y1 += mapscreen_y;
5784 safe_rect(screen, x0, y0, x1, y1, showxypos_cursor_color);
5785 }
5786
5787 // Draw dithering over the edge/preview combos.
5788 if(showedges)
5789 {
5790 int tile_size = 16 * mapscreen_single_scale;
5791 int tiles_across = (16 * Map.getViewSize()) + 2;
5792 int bottom_row_y = (Map.getViewSize()*11 + 1) * tile_size;
5793 int right_col_x = (Map.getViewSize()*16 + 1) * tile_size;
5794
5795 //top preview
5796 for(int32_t j=0; j<tile_size; j++)
5797 {
5798 for(int32_t i=0; i<tiles_across * tile_size; i++)
5799 {
5800 if(((i^j)&1)==0)
5801 {
5802 putpixel(screen,mapscreen_x+i,mapscreen_y+j,vc(0));
5803 }
5804 }
5805 }
5806
5807 //bottom preview
5808 for(int32_t j = bottom_row_y; j < bottom_row_y + tile_size; j++)
5809 {
5810 for(int32_t i=0; i<tiles_across * tile_size; i++)
5811 {
5812 if(((i^j)&1)==0)
5813 {
5814 putpixel(screen,mapscreen_x+i,mapscreen_y+j,vc(0));
5815 }
5816 }
5817 }
5818
5819 //left preview
5820 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5821 {
5822 for(int32_t i=0; i<16*mapscreen_single_scale; i++)
5823 {
5824 if(((i^j)&1)==0)
5825 {
5826 putpixel(screen,mapscreen_x+i,mapscreen_y+j,vc(0));
5827 }
5828 }
5829 }
5830
5831 //right preview
5832 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5833 {
5834 for(int32_t i = right_col_x; i < right_col_x + tile_size; i++)
5835 {
5836 if(((i^j)&1)==0)
5837 {
5838 putpixel(screen,mapscreen_x+i,mapscreen_y+j,vc(0));
5839 }
5840 }
5841 }
5842 }
5843
5844 if(!(Flags&cDEBUG) && pixeldb==2)
5845 {
5846 for(int32_t j=int32_t(168*mapscreen_single_scale); j<int32_t(176*mapscreen_single_scale); j++)
5847 {
5848 for(int32_t i=0; i<int32_t(256*mapscreen_single_scale); i++)
5849 {
5850
5851 if(((i^j)&1)==0)
5852 {
5853 putpixel(screen,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0)+i),
5854 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5855 }
5856 }
5857 }
5858 }
5859
5860 // TODO: This should move to `zmap::draw` (and delete the current code there doing a similar thing).
5861 if (Map.isDark(Map.getCurrScr()) && Map.getViewSize() == 1)
5862 {
5863 if((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM))
5864 {
5865 BITMAP* tmpDark = create_bitmap_ex(8,16*16,16*11);
5866 BITMAP* tmpDarkTrans = create_bitmap_ex(8,16*16,16*11);
5867 BITMAP* tmpbuf = create_bitmap_ex(8,
5868 mapscreen_single_scale*(256+(showedges?32:0)),
5869 mapscreen_single_scale*(176+(showedges?32:0)));
5870 BITMAP* tmpbuf2 = create_bitmap_ex(8,
5871 mapscreen_single_scale*(256+(showedges?32:0)),
5872 mapscreen_single_scale*(176+(showedges?32:0)));
5873 int32_t darkCol = zinit.darkcol;
5874 switch(darkCol) //special cases
5875 {
5876 case BLACK:
5877 darkCol = vc(0);
5878 break;
5879 case WHITE:
5880 darkCol = vc(15);
5881 break;
5882 }
5883 clear_to_color(tmpDark, darkCol);
5884 clear_to_color(tmpDarkTrans, darkCol);
5885 clear_bitmap(tmpbuf);
5886 clear_bitmap(tmpbuf2);
5887 //Handle torch combos
5888 color_map = trans_table2;
5889 Map.draw_darkness(tmpDark, tmpDarkTrans);
5890 //
5891 mapscr* tmp = Map.CurrScr();
5892 if(tmp->flags9 & fDARK_DITHER)
5893 {
5894 ditherblit(tmpDark, tmpDark, 0, zinit.dither_type, zinit.dither_arg);
5895 ditherblit(tmpDarkTrans, tmpDarkTrans, 0, zinit.dither_type, zinit.dither_arg);
5896 }
5897
5898 if(mapscreen_single_scale == 1)
5899 {
5900 blit(tmpDark, tmpbuf, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5901 blit(tmpDarkTrans, tmpbuf2, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5902 }
5903 else
5904 {
5905 stretch_blit(tmpDark, tmpbuf, 0, 0, 16*16, 16*11,
5906 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5907 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5908 stretch_blit(tmpDarkTrans, tmpbuf2, 0, 0, 16*16, 16*11,
5909 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5910 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5911 }
5912
5913 if(tmp->flags9 & fDARK_TRANS)
5914 {
5915 draw_trans_sprite(screen, tmpbuf, mapscreen_x, mapscreen_y);
5916 }
5917 else
5918 {
5919 masked_blit(tmpbuf,screen,0,0,mapscreen_x,mapscreen_y,tmpbuf->w,tmpbuf->h);
5920 }
5921 draw_trans_sprite(screen, tmpbuf2, mapscreen_x, mapscreen_y);
5922 color_map = trans_table;
5923 //
5924 destroy_bitmap(tmpDark);
5925 destroy_bitmap(tmpDarkTrans);
5926 destroy_bitmap(tmpbuf);
5927 destroy_bitmap(tmpbuf2);
5928 }
5929 else if(!(Flags&cNODARK))
5930 {
5931 for(int32_t j=0; j<80*mapscreen_single_scale; j++)
5932 {
5933 for(int32_t i=0; i<(80*mapscreen_single_scale)-j; i++)
5934 {
5935 if(((i^j)&1)==0)
5936 {
5937 putpixel(screen,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0))+i,
5938 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5939 }
5940 }
5941 }
5942 }
5943 }
5944
5945 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
5946 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
5947 bool inrect = isinRect(gui_mouse_x(),gui_mouse_y(),startx,starty,(startx+(256*mapscreen_screenunit_scale)-1),(starty+(176*mapscreen_screenunit_scale)-1));
5948
5949 if(!(flags&rNOCURSOR) && ((ComboBrush && !ComboBrushPause)||draw_mode==dm_alias) && inrect)
5950 {
5951 int mgridscale=16*mapscreen_single_scale;
5952 if(allowHideMouse)
5953 {
5954 if(arrowcursor)
5955 {
5956 arrowcursor = false;
5957 MouseSprite::set(ZQM_BLANK);
5958 }
5959 }
5960 else if(!arrowcursor)
5961 {
5962 arrowcursor = true;
5963 MouseSprite::set(ZQM_NORMAL);
5964 }
5965 ComboPosition pos = get_mapscreen_mouse_combo_pos();
5966 int32_t mx = pos.x * 16 * mapscreen_single_scale;
5967 int32_t my = pos.y * 16 * mapscreen_single_scale;
5968
5969 clear_bitmap(brushscreen);
5970 int32_t tempbw=BrushWidth;
5971 int32_t tempbh=BrushHeight;
5972
5973 if(draw_mode==dm_alias)
5974 {
5975 BrushWidth = combo_aliases[combo_apos].width+1;
5976 BrushHeight = combo_aliases[combo_apos].height+1;
5977 }
5978 else if(draw_mode == dm_cpool)
5979 {
5980 BrushWidth = BrushHeight = 1;
5981 combo_pool const& pool = combo_pools[combo_pool_pos];
5982 if(pool.valid())
5983 {
5984 int32_t cid = Combo;
5985 int8_t cset = CSet;
5986 pool.get_w_wrap(cid,cset,cpoolbrush_index/16); //divide to reduce speed
5987 put_combo(brushbmp,0,0,cid,cset,Flags&(cFLAGS|cWALK),0);
5988 }
5989 else clear_bitmap(brushbmp);
5990 }
5991 else if (draw_mode == dm_auto)
5992 {
5993 BrushWidth = BrushHeight = 1;
5994 }
5995
5996 stretch_blit(brushbmp, brushscreen, 0, 0, BrushWidth*16, BrushHeight*16, 0, 0, BrushWidth*mgridscale, BrushHeight*mgridscale);
5997 int float_offx = 0;
5998 int float_offy = 0;
5999
6000 if(FloatBrush)
6001 {
6002 float_offx = -SHADOW_DEPTH*mapscreen_single_scale;
6003 float_offy = -SHADOW_DEPTH*mapscreen_single_scale;
6004
6005 //shadow
6006 for(int x = 0; x < SHADOW_DEPTH*mapscreen_single_scale; ++x)
6007 for(int y = 0; y < (BrushHeight*mgridscale) + (SHADOW_DEPTH*mapscreen_single_scale); ++y)
6008 {
6009 if((((x^y)&1)==1) && y < 12*mgridscale)
6010 putpixel(brushscreen,x+(BrushWidth*mgridscale),y,vc(0));
6011 }
6012
6013 for(int x = 0; x < BrushWidth*mgridscale; ++x)
6014 for(int y = 0; y < SHADOW_DEPTH*mapscreen_single_scale; ++y)
6015 {
6016 if((((x^y)&1)==1) && x<16*mgridscale)
6017 putpixel(brushscreen,x,y+(BrushHeight*mgridscale),vc(0));
6018 }
6019 }
6020
6021 if(draw_mode==dm_alias)
6022 {
6023 combo_alias *combo = &combo_aliases[combo_apos];
6024
6025 if(BrushWidth > 1 && (alias_origin & 1)) //right-align
6026 float_offx -= (BrushWidth - 1) * mgridscale;
6027
6028 if(BrushHeight > 1 && (alias_origin & 2)) //bottom-align
6029 float_offy -= (BrushHeight - 1) * mgridscale;
6030 }
6031
6032 int bx = mapscreen_x + mx + float_offx + (showedges?(16*mapscreen_single_scale):0);
6033 int by = mapscreen_y + my + float_offy + (showedges?(16*mapscreen_single_scale):0);
6034 masked_blit(brushscreen, screen, 0, 0, bx, by, 16*mgridscale, 11*mgridscale);
6035 BrushWidth=tempbw;
6036 BrushHeight=tempbh;
6037 }
6038 else
6039 {
6040 if(!arrowcursor)
6041 {
6042 MouseSprite::set(ZQM_NORMAL);
6043 arrowcursor = true;
6044 }
6045 }
6046
6047 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
6048 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
6049 int endxint = startx + 256*mapscreen_screenunit_scale - 1;
6050 int endyint = starty + 176*mapscreen_screenunit_scale - 1;
6051 set_clip_rect(screen,startxint,startyint,endxint,endyint);
6052
6053 if(ShowGrid)
6054 {
6055 int w = num_combos_width;
6056 int h = num_combos_height;
6057 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
6058
6059 if(showedges)
6060 {
6061 w += 2;
6062 h += 2;
6063 }
6064
6065 for (int x = 1; x < w; x++)
6066 {
6067 vline(screen, mapscreen_x + x*tile_size, mapscreen_y, mapscreen_y + (h*tile_size)-1, vc(GridColor));
6068 }
6069
6070 for (int y = 1; y < h; y++)
6071 {
6072 hline(screen, mapscreen_x, mapscreen_y + y*tile_size, mapscreen_x + (w*tile_size)-1, vc(GridColor));
6073 }
6074 }
6075
6076 if(ShowScreenGrid)
6077 {
6078 int w = num_combos_width;
6079 int h = num_combos_height;
6080 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
6081 int startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
6082 int starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
6083
6084 if(showedges)
6085 {
6086 w += 1;
6087 h += 1;
6088 }
6089
6090 int color = (GridColor+8)%16;
6091
6092 for (int x = 16; x < w; x+=16)
6093 {
6094 vline(screen, startx + x*tile_size, mapscreen_y, starty + (h*tile_size)-1, vc(color));
6095 }
6096
6097 for (int y = 11; y < h; y+=11)
6098 {
6099 hline(screen, startx, starty + y*tile_size, startx + (w*tile_size)-1, vc(color));
6100 }
6101 }
6102
6103 // Draw a rect around regions.
6104 if (ShowRegionGrid && Map.getViewSize() > 1)
6105 {
6106 for (const auto& region_description : Map.get_region_descriptions())
6107 {
6108 int sx = region_description.screen % 16;
6109 int sy = region_description.screen / 16;
6110 int sw = region_description.w;
6111 int sh = region_description.h;
6112
6113 int mw = 256 * mapscreen_single_scale;
6114 int mh = 176 * mapscreen_single_scale;
6115 int mx = sx - (Map.getViewScr() % 16);
6116 int my = sy - (Map.getViewScr() / 16);
6117 int x0 = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0) + mx * mw;
6118 int y0 = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0) + my * mh;
6119 rect(screen, x0+2, y0+2, x0 + mw*sw - 2, y0 + mh*sh - 2, vc(1));
6120 rect(screen, x0+1, y0+1, x0 + mw*sw - 1, y0 + mh*sh - 1, vc(15));
6121 rect(screen, x0, y0, x0 + mw*sw, y0 + mh*sh, vc(1));
6122 }
6123 }
6124
6125 // Draw a black-yellow-black rect around the currently selected screen.
6126 if (ShowCurScreenOutline && Map.getViewSize() > 1)
6127 {
6128 int mw = 256 * mapscreen_single_scale;
6129 int mh = 176 * mapscreen_single_scale;
6130 int mx = (Map.getCurrScr() % 16) - (Map.getViewScr() % 16);
6131 int my = (Map.getCurrScr() / 16) - (Map.getViewScr() / 16);
6132 int x0 = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0) + mx * mw;
6133 int y0 = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0) + my * mh;
6134 dotted_rect(screen, x0+2, y0+2, x0 + mw - 2, y0 + mh - 2, vc(1), vc(0));
6135 rect(screen, x0+1, y0+1, x0 + mw - 1, y0 + mh - 1, vc(14));
6136 dotted_rect(screen, x0, y0, x0 + mw, y0 + mh, vc(1), vc(0));
6137 }
6138
6139 clear_clip_rect(screen);
6140
6141 // Map tabs
6142 font = get_custom_font(CFONT_GUI);
6143
6144 map_page[current_mappage].map=Map.getCurrMap();
6145 map_page[current_mappage].screen=Map.getCurrScr();
6146
6147 for(int32_t btn=0; btn<mappage_count; ++btn)
6148 {
6149 char tbuf[15];
6150 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
6151 draw_layer_button(screen,map_page_bar[btn].x, map_page_bar[btn].y, map_page_bar[btn].w, map_page_bar[btn].h,tbuf,(btn==current_mappage?D_SELECTED:0));
6152 }
6153 }
6154 break;
6155 case rCOMBOS:
6156 {
6157 auto real_h = combolist_window.h;
6158 jwin_draw_frame(screen,combolist_window.x,combolist_window.y,combolist_window.w,real_h, FR_WIN);
6159 rectfill(screen,combolist_window.x+2,combolist_window.y+2,combolist_window.x+combolist_window.w-3,combolist_window.y+real_h-3,jwin_pal[jcBOX]);
6160
6161 //Scrollers
6162 for(int32_t c = 0; c < num_combo_cols; ++c)
6163 {
6164 auto& pos = combolistscrollers[c];
6165
6166 { //Scroll up
6167 auto& p = pos.subsquare(0);
6168 jwin_draw_frame(screen,p.x,p.y,p.w,p.h,FR_ETCHED);
6169
6170 for(int32_t i=0; i<3; i++)
6171 {
6172 hline(screen, p.x+5-i, p.y+4+i, p.x+5+i, jwin_pal[jcBOXFG]);
6173 }
6174 }
6175
6176 { //Scroll down
6177 auto& p = pos.subsquare(1);
6178 jwin_draw_frame(screen,p.x,p.y,p.w,p.h,FR_ETCHED);
6179
6180 for(int32_t i=0; i<3; i++)
6181 {
6182 hline(screen,p.x+5-i,p.y+6-i, p.x+5+i, jwin_pal[jcBOXFG]);
6183 }
6184 }
6185 }
6186
6187 if(draw_mode==dm_alias)
6188 {
6189 if(LinkedScroll)
6190 {
6191 int tmp = current_comboalist;
6192 for(int q = tmp-1; q >= 0; --q)
6193 {
6194 combo_alistpos[q] = combo_alistpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6195 if(combo_alistpos[q] < 0)
6196 {
6197 tmp = 0;
6198 combo_alistpos[0] = 0;
6199 break;
6200 }
6201 }
6202 for(int q = tmp+1; q < num_combo_cols; ++q)
6203 combo_alistpos[q] = combo_alistpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6204 for(int q = 0; q < num_combo_cols; ++q)
6205 if(combo_apos >= combo_alistpos[q] && combo_apos < combo_alistpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6206 {
6207 current_comboalist = q;
6208 break;
6209 }
6210 }
6211 for(int32_t c = 0; c < num_combo_cols; ++c)
6212 {
6213 auto& pos = comboaliaslist[c];
6214 rectfill(screen,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6215 jwin_draw_frame(screen,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6216 }
6217
6218 auto& prev = comboalias_preview;
6219 jwin_draw_frame(screen, prev.x-2, prev.y-2, prev.w+4, prev.h+4,FR_DEEP);
6220
6221 BITMAP *prv = create_bitmap_ex(8,64,64);
6222 clear_bitmap(prv);
6223 int32_t scalefactor = 1;
6224
6225 for(int32_t j=0; j<num_combo_cols; ++j)
6226 {
6227 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6228 if(combo_alistpos[j] + per_page >= MAXCOMBOALIASES)
6229 combo_alistpos[j] = MAXCOMBOALIASES-per_page;
6230 auto& col = comboaliaslist[j];
6231 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6232 {
6233 draw_combo_alias_thumbnail(screen, &combo_aliases[combo_alistpos[j]+i],
6234 (i%col.w)*col.xscale+col.x, (i/col.w)*col.yscale+col.y, col.xscale/16);
6235 }
6236
6237 if((combo_aliases[combo_apos].width>7)||(combo_aliases[combo_apos].height>7))
6238 {
6239 scalefactor=4;
6240 }
6241 else if((combo_aliases[combo_apos].width>3)||(combo_aliases[combo_apos].height>3))
6242 {
6243 scalefactor=2;
6244 }
6245
6246
6247 if(j==current_comboalist)
6248 {
6249 stretch_blit(brushbmp, prv, 0,0,scalefactor*64,zc_min(scalefactor*64,176),0,0,64,scalefactor==4?44:64);
6250 blit(prv,screen,0,0,comboalias_preview.x,comboalias_preview.y,comboalias_preview.w,comboalias_preview.h);
6251
6252 int32_t rect_pos=combo_apos-combo_alistpos[current_comboalist];
6253
6254 if((rect_pos>=0)&&(rect_pos<(combo_alistpos[current_comboalist]+(col.w*col.h))))
6255 {
6256 int selw = col.xscale;
6257 int selh = col.yscale;
6258 int x1 = (rect_pos&(col.w-1))*col.xscale+col.x;
6259 int y1 = (rect_pos/col.w)*col.yscale+col.y;
6260 safe_rect(screen,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6261 }
6262 }
6263 }
6264
6265 destroy_bitmap(prv);
6266 }
6267 else if(draw_mode==dm_cpool)
6268 {
6269 if(LinkedScroll)
6270 {
6271 int tmp = current_cpoollist;
6272 for(int q = tmp-1; q >= 0; --q)
6273 {
6274 combo_pool_listpos[q] = combo_pool_listpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6275 if(combo_pool_listpos[q] < 0)
6276 {
6277 tmp = 0;
6278 combo_pool_listpos[0] = 0;
6279 break;
6280 }
6281 }
6282 for(int q = tmp+1; q < num_combo_cols; ++q)
6283 combo_pool_listpos[q] = combo_pool_listpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6284 for(int q = 0; q < num_combo_cols; ++q)
6285 if(combo_pool_pos >= combo_pool_listpos[q] && combo_pool_pos < combo_pool_listpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6286 {
6287 current_cpoollist = q;
6288 break;
6289 }
6290 }
6291 for(int32_t c = 0; c < num_combo_cols; ++c)
6292 {
6293 auto& pos = comboaliaslist[c];
6294 rectfill(screen,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6295 jwin_draw_frame(screen,pos.x-2,pos.y-2,(pos.w*comboaliaslist[c].xscale)+4,(pos.h*comboaliaslist[c].yscale)+4,FR_DEEP);
6296 }
6297
6298 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6299 {
6300 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6301 if(combo_pool_listpos[j] + per_page >= MAXCOMBOPOOLS)
6302 combo_pool_listpos[j] = MAXCOMBOPOOLS-per_page;
6303 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6304 {
6305 int32_t cid=-1; int8_t cs=CSet;
6306 combo_pool const& cp = combo_pools[combo_pool_listpos[j]+i];
6307
6308 auto& list = comboaliaslist[j];
6309 if(cp.get_w(cid,cs,0) && !combobuf[cid].tile)
6310 {
6311 cid = -1; //no tile to draw
6312 }
6313 auto cx = (i%list.w)*list.xscale+list.x;
6314 auto cy = (i/list.w)*list.yscale+list.y;
6315 put_combo(screen,cx,cy,cid,cs,Flags&(cFLAGS|cWALK),0,list.xscale/16);
6316 }
6317 }
6318 int32_t rect_pos=combo_pool_pos-combo_pool_listpos[current_cpoollist];
6319
6320 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_cpoollist]+(comboaliaslist[current_cpoollist].w*comboaliaslist[current_cpoollist].h))))
6321 {
6322 int selw = comboaliaslist[current_cpoollist].xscale;
6323 int selh = comboaliaslist[current_cpoollist].yscale;
6324 int x1 = (rect_pos&(comboaliaslist[current_cpoollist].w-1))*comboaliaslist[current_cpoollist].xscale+comboaliaslist[current_cpoollist].x;
6325 int y1 = (rect_pos/comboaliaslist[current_cpoollist].w)*comboaliaslist[current_cpoollist].yscale+comboaliaslist[current_cpoollist].y;
6326 safe_rect(screen,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6327 }
6328
6329 //Handle Preview
6330 combo_pool const& cpool = combo_pools[combo_pool_pos];
6331
6332 int32_t cid; int8_t cs;
6333 size_t total = weighted_cpool ? cpool.getTotalWeight() : cpool.combos.size();
6334 size_t ind = 0;
6335 size_t indw = combopool_preview.w/16;
6336 size_t indh = combopool_preview.h/16;
6337 size_t rows = total ? vbound(total/indw,1,indh) : 0;
6338 if (is_compact)
6339 rows = vbound(rows, 1, 3);
6340 else
6341 rows = vbound(rows, 1, 4);
6342 size_t real_height = rows*16;
6343
6344 cpool_prev_visible = rows > 0;
6345 if(rows)
6346 {
6347 jwin_draw_frame(screen,combopool_preview.x-2,combopool_preview.y-2,
6348 combopool_preview.w+4,real_height+4,FR_DEEP);
6349 rectfill(screen,combopool_preview.x,combopool_preview.y,
6350 combopool_preview.x+combopool_preview.w-1,
6351 combopool_preview.y+real_height-1,vc(0));
6352 draw_text_button(screen,combopool_prevbtn.x,combopool_prevbtn.y,
6353 combopool_prevbtn.w,combopool_prevbtn.h,
6354 weighted_cpool ? "Weighted" : "Unweighted",vc(1),vc(14),0,true);
6355 if(!is_compact)
6356 textprintf_ex(screen,font,combopool_prevbtn.x+combopool_prevbtn.w+5,
6357 combopool_prevbtn.y,jwin_pal[jcBOXFG],-1,"Preview");
6358 for(auto y = 0; y < real_height; y += 16)
6359 {
6360 for(auto x = 0; x < combopool_preview.w; x += 16, ++ind)
6361 {
6362 auto nx = combopool_preview.x+x, ny = combopool_preview.y+y;
6363 if(ind < total)
6364 {
6365 cs = CSet;
6366 if(weighted_cpool
6367 ? cpool.get_w(cid,cs,ind)
6368 : cpool.get_ind(cid,cs,ind))
6369 {
6370 put_combo(screen,nx,ny,cid,cs,Flags&(cFLAGS|cWALK),0);
6371 continue;
6372 }
6373 }
6374 //No combo to display
6375 xout(screen, nx, ny, nx+15, ny+15, vc(15));
6376 }
6377 }
6378 }
6379 }
6380 else if (draw_mode == dm_auto)
6381 {
6382 if (LinkedScroll)
6383 {
6384 int tmp = current_cautolist;
6385 for (int q = tmp - 1; q >= 0; --q)
6386 {
6387 combo_auto_listpos[q] = combo_auto_listpos[q + 1] - (comboaliaslist[q].w * comboaliaslist[q].h);
6388 if (combo_auto_listpos[q] < 0)
6389 {
6390 tmp = 0;
6391 combo_auto_listpos[0] = 0;
6392 break;
6393 }
6394 }
6395 for (int q = tmp + 1; q < num_combo_cols; ++q)
6396 combo_auto_listpos[q] = combo_auto_listpos[q - 1] + (comboaliaslist[q - 1].w * comboaliaslist[q - 1].h);
6397 for (int q = 0; q < num_combo_cols; ++q)
6398 if (combo_auto_pos >= combo_auto_listpos[q] && combo_auto_pos < combo_auto_listpos[q] + (comboaliaslist[q].w * comboaliaslist[q].h))
6399 {
6400 current_cautolist = q;
6401 break;
6402 }
6403 }
6404 for (int32_t c = 0; c < num_combo_cols; ++c)
6405 {
6406 auto& pos = comboaliaslist[c];
6407 rectfill(screen, pos.x, pos.y, pos.x + (pos.w * pos.xscale) - 1, pos.y + (pos.h * pos.yscale) - 1, 0);
6408 jwin_draw_frame(screen, pos.x - 2, pos.y - 2, (pos.w * comboaliaslist[c].xscale) + 4, (pos.h * comboaliaslist[c].yscale) + 4, FR_DEEP);
6409 }
6410
6411 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6412 {
6413 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6414 if(combo_auto_listpos[j] + per_page >= MAXAUTOCOMBOS)
6415 combo_auto_listpos[j] = MAXAUTOCOMBOS-per_page;
6416 for (int32_t i = 0; i < (comboaliaslist[j].w * comboaliaslist[j].h); i++)
6417 {
6418 int32_t cid = -1; int8_t cs = CSet;
6419 combo_auto const& ca = combo_autos[combo_auto_listpos[j] + i];
6420
6421 auto& list = comboaliaslist[j];
6422 cid = ca.getDisplay();
6423 if (cid == 0)
6424 cid = -1;
6425 auto cx = (i % list.w) * list.xscale + list.x;
6426 auto cy = (i / list.w) * list.yscale + list.y;
6427 put_combo(screen, cx, cy, cid, cs, Flags & (cFLAGS | cWALK), 0, list.xscale / 16);
6428 put_autocombo_engravings(screen, ca, combo_auto_listpos[j] + i == combo_auto_pos, cx, cy, list.xscale / 16);
6429 }
6430 }
6431 int32_t rect_pos = combo_auto_pos - combo_auto_listpos[current_cautolist];
6432
6433 if ((rect_pos >= 0) && (rect_pos < (combo_auto_listpos[current_cautolist] + (comboaliaslist[current_cautolist].w * comboaliaslist[current_cautolist].h))))
6434 {
6435 int selw = comboaliaslist[current_cautolist].xscale;
6436 int selh = comboaliaslist[current_cautolist].yscale;
6437 int x1 = (rect_pos & (comboaliaslist[current_cautolist].w - 1)) * comboaliaslist[current_cautolist].xscale + comboaliaslist[current_cautolist].x;
6438 int y1 = (rect_pos / comboaliaslist[current_cautolist].w) * comboaliaslist[current_cautolist].yscale + comboaliaslist[current_cautolist].y;
6439 safe_rect(screen, x1, y1, x1 + selw - 1, y1 + selh - 1, vc(CmbCursorCol), 2);
6440
6441 combo_auto const& ca = combo_autos[combo_auto_pos];
6442 put_autocombo_engravings(screen, ca, true, x1, y1, selw / 16);
6443 }
6444 }
6445 else
6446 {
6447 if(LinkedScroll)
6448 {
6449 int tmp = current_combolist;
6450 for(int q = tmp-1; q >= 0; --q)
6451 {
6452 First[q] = First[q+1]-(combolist[q].w*combolist[q].h);
6453 if(First[q] < 0)
6454 {
6455 tmp = 0;
6456 First[0] = 0;
6457 break;
6458 }
6459 }
6460 for(int q = tmp+1; q < num_combo_cols; ++q)
6461 First[q] = First[q-1]+(combolist[q-1].w*combolist[q-1].h);
6462 for(int q = 0; q < num_combo_cols; ++q)
6463 if(Combo >= First[q] && Combo < First[q] + (combolist[q].w*combolist[q].h))
6464 {
6465 current_combolist = q;
6466 break;
6467 }
6468 }
6469 for(int32_t c = 0; c < num_combo_cols; ++c)
6470 {
6471 auto& pos = combolist[c];
6472 rectfill(screen,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6473 jwin_draw_frame(screen,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6474 }
6475
6476 int32_t drawmap, drawscr;
6477 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6478 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6479
6480 for(int32_t j=0; j<num_combo_cols; ++j)
6481 {
6482 auto per_page = (combolist[j].w * combolist[j].h);
6483 if(First[j] + per_page >= MAXCOMBOS)
6484 First[j] = MAXCOMBOS-per_page;
6485 for(int32_t i=0; i<(combolist[j].w*combolist[j].h); i++)
6486 {
6487 put_combo(screen,(i%combolist[j].w)*combolist[j].xscale+combolist[j].x,
6488 (i/combolist[j].w)*combolist[j].yscale+combolist[j].y,
6489 i+First[j],CSet,Flags&(cFLAGS|cWALK),0,combolist[j].xscale/16);
6490 }
6491 }
6492
6493 int32_t rect_pos=Combo-First[current_combolist];
6494
6495 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_combolist]+(combolist[current_combolist].w*combolist[current_combolist].h))))
6496 {
6497 int selw = (AutoBrush?BrushWidth:1)*combolist[current_combolist].xscale;
6498 int selh = (AutoBrush?BrushHeight:1)*combolist[current_combolist].yscale;
6499 int x1 = (rect_pos&(combolist[current_combolist].w-1))*combolist[current_combolist].xscale+combolist[current_combolist].x;
6500 int y1 = (rect_pos/combolist[current_combolist].w)*combolist[current_combolist].yscale+combolist[current_combolist].y;
6501 safe_rect(screen,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6502 }
6503 }
6504 }
6505 break;
6506 case rCOMBO:
6507 {
6508 int32_t drawmap, drawscr;
6509 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6510 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6511
6512 // Combo preview
6513 int32_t cid = Combo; int8_t cs = CSet;
6514 if(draw_mode == dm_alias)
6515 {
6516 cid = combo_aliases[combo_apos].combos[0];
6517 cs = wrap(combo_aliases[combo_apos].csets[0]+alias_cset_mod, 0, 13);
6518 }
6519 else if(draw_mode == dm_cpool)
6520 {
6521 combo_pool const& cpool = combo_pools[combo_pool_pos];
6522 cid = 0;
6523 cpool.get_w(cid,cs,0);
6524 }
6525 else if (draw_mode == dm_auto)
6526 {
6527 combo_auto const& cauto = combo_autos[combo_auto_pos];
6528 cid = cauto.getDisplay();
6529 }
6530 static BITMAP *combo_preview_bmp=create_bitmap_ex(8,32,32);
6531 static BITMAP *cycle_preview_bmp=create_bitmap_ex(8,32,32);
6532 // Combo
6533 put_combo(combo_preview_bmp,0,0,cid,cs,Flags&(cFLAGS|cWALK),0);
6534 jwin_draw_frame(screen,combo_preview.x-2,combo_preview.y-2,combo_preview.w+4,combo_preview.h+4, FR_DEEP);
6535 stretch_blit(combo_preview_bmp, screen, 0, 0, 16, 16, combo_preview.x, combo_preview.y, combo_preview.w, combo_preview.h);
6536
6537 comboprev_buf[0] = 0;
6538 comboprev_buf2[0] = 0;
6539 if(draw_mode == dm_cpool)
6540 {
6541 sprintf(comboprev_buf,"Pool: %d\nCSet: %d",combo_pool_pos,CSet);
6542 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6543 textbox_out(screen,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],comboprev_buf,2,&combo_preview_text1);
6544 }
6545 else if (draw_mode == dm_auto)
6546 {
6547 GUI::ListData ac_types = GUI::ZCListData::autocombotypes();
6548 std::string type_name = ac_types.findText(combo_autos[combo_auto_pos].getType());
6549 if (is_compact)
6550 sprintf(comboprev_buf, "AC: %d CS: %d\n%s", combo_auto_pos, CSet, type_name.c_str());
6551 else
6552 sprintf(comboprev_buf, "Auto: %d CSet: %d\n%s\nEntries: %d", combo_auto_pos, CSet, type_name.c_str(), int32_t(combo_autos[combo_auto_pos].combos.size()));
6553 int x = combo_preview_text1.x + (combo_preview_text1.w * combo_preview_text1.xscale);
6554 textbox_out(screen, txfont, x, combo_preview_text1.y, jwin_pal[jcBOXFG], jwin_pal[jcBOX], comboprev_buf, 2, &combo_preview_text1);
6555 }
6556 else if(draw_mode != dm_alias)
6557 {
6558 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6559
6560 char shortbuf[512];
6561 char buf[256];
6562 strcpy(buf,combo_class_buf[combobuf[Combo].type].name);
6563 sprintf(comboprev_buf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6564 int ind = strlen(buf)-1;
6565 int x2 = x;
6566 if(x2 - text_length(txfont, buf) <= combolist_window.x)
6567 {
6568 auto dotlen = text_length(txfont, "..");
6569 x2 -= dotlen;
6570 while(x2 - text_length(txfont, buf) <= combolist_window.x)
6571 {
6572 if(ind < 0) break;
6573 buf[ind--] = '\0';
6574 }
6575 while(ind >= 0 && buf[ind] == ' ')
6576 buf[ind--] = 0; //trim spaces
6577 strcat(buf, "..");
6578 }
6579
6580 if(is_compact)
6581 {
6582 char b2[256];
6583 sprintf(b2, "Combo %d CS %d", Combo, CSet);
6584 if(x-text_length(txfont, b2) <= combolist_window.x)
6585 sprintf(b2, "Cmb %d CS %d", Combo, CSet);
6586 sprintf(shortbuf,"%s\n%s",b2,buf);
6587 }
6588 else sprintf(shortbuf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6589 textbox_out(screen,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,2,&combo_preview_text1);
6590 }
6591
6592 // Cycle
6593 if(!is_compact)
6594 {
6595 int32_t NextCombo = combobuf[Combo].nextcombo;
6596 int32_t NextCSet = combobuf[Combo].nextcset;
6597 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
6598 {
6599 mapscr* scr = Map.CurrScr();
6600 NextCombo = scr->undercombo;
6601 NextCSet = scr->undercset;
6602 }
6603 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
6604 NextCSet = CSet;
6605 bool normal_dm = draw_mode != dm_alias && draw_mode != dm_cpool && draw_mode != dm_auto;
6606 jwin_draw_frame(screen,combo_preview2.x-2,combo_preview2.y-2,combo_preview2.w+4,combo_preview2.h+4, FR_DEEP);
6607 if(NextCombo>0 && normal_dm)
6608 {
6609 put_combo(cycle_preview_bmp,0,0,NextCombo,NextCSet,Flags&(cFLAGS|cWALK),0);
6610
6611 if(Flags&cWALK) put_walkflags(cycle_preview_bmp,0,0,NextCombo,0);
6612
6613 if(Flags&cFLAGS) put_flags(cycle_preview_bmp,0,0,NextCombo,0,cFLAGS,0);
6614
6615 stretch_blit(cycle_preview_bmp, screen, 0, 0, 16, 16, combo_preview2.x, combo_preview2.y, combo_preview2.w, combo_preview2.h);
6616 }
6617 else
6618 {
6619 if (InvalidBG == 2)
6620 {
6621 draw_checkerboard(screen, combo_preview2.x, combo_preview2.y, 32);
6622 }
6623 else if(InvalidBG == 1)
6624 {
6625 draw_static_pos(combo_preview2);
6626 }
6627 else
6628 {
6629 rectfill(screen, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(0));
6630 safe_rect(screen, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6631 line(screen, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6632 line(screen, combo_preview2.x,combo_preview2.y+combo_preview2.h, combo_preview2.x+32,combo_preview2.y,vc(15));
6633 }
6634 }
6635
6636 if(normal_dm)
6637 {
6638 char shortbuf[512];
6639 char buf[256];
6640 strcpy(buf,combo_class_buf[combobuf[NextCombo].type].name);
6641 sprintf(comboprev_buf2, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6642 int ind = strlen(buf)-1;
6643 int x2 = combo_preview_text2.x;
6644 if(x2 + text_length(txfont, buf) > zq_screen_w-2)
6645 {
6646 auto dotlen = text_length(txfont, "..");
6647 x2 += dotlen;
6648 while(x2 + text_length(txfont, buf) > zq_screen_w-2)
6649 {
6650 if(ind < 0) break;
6651 buf[ind--] = '\0';
6652 }
6653 while(ind >= 0 && buf[ind] == ' ')
6654 buf[ind--] = 0; //trim spaces
6655 strcat(buf, "..");
6656 }
6657
6658 sprintf(shortbuf, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6659 textbox_out(screen,txfont,combo_preview_text2.x,combo_preview_text2.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,0,&combo_preview_text2);
6660 }
6661 }
6662
6663 font = get_zc_font(font_lfont_l);
6664 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
6665 draw_text_button(screen,combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<",vc(1),vc(14),0,true);
6666 }
6667 break;
6668 case rFAVORITES:
6669 {
6670 font = get_zc_font(font_lfont_l);
6671
6672 jwin_draw_frame(screen,favorites_window.x,favorites_window.y,favorites_window.w,favorites_window.h, FR_WIN);
6673 rectfill(screen,favorites_window.x+2,favorites_window.y+2,favorites_window.x+favorites_window.w-3,favorites_window.y+favorites_window.h-3,jwin_pal[jcBOX]);
6674 jwin_draw_frame(screen,favorites_list.x-2,favorites_list.y-2,(favorites_list.w*favorites_list.xscale)+4,(favorites_list.h*favorites_list.yscale)+4, FR_DEEP);
6675 rectfill(screen,favorites_list.x,favorites_list.y,favorites_list.x+(favorites_list.w*favorites_list.xscale)-1,favorites_list.y+(favorites_list.h*favorites_list.yscale)-1,jwin_pal[jcBOXFG]);
6676
6677 textprintf_ex(screen,get_zc_font(font_lfont_l),favorites_list.x-2,favorites_list.y-15,jwin_pal[jcBOXFG],-1,is_compact ? "Favorites" : "Favorite Combos");
6678 BITMAP* subb = create_bitmap_ex(8,16,16);
6679
6680 for(int32_t col=0; col<favorites_list.w; ++col)
6681 {
6682 for(int32_t row=0; row<favorites_list.h; ++row)
6683 {
6684 auto i = (row*FAVORITECOMBO_PER_ROW)+col+FAVORITECOMBO_PER_PAGE*FavoriteComboPage;
6685 auto& sqr = favorites_list.subsquare(col,row);
6686 if(i >= MAXFAVORITECOMBOS || favorite_combos[i]==-1)
6687 {
6688 if (InvalidBG == 2)
6689 {
6690 draw_checkerboard(screen, sqr.x, sqr.y, sqr.w);
6691 }
6692 else if(InvalidBG == 1)
6693 {
6694 draw_static_pos(sqr);
6695 }
6696 else
6697 {
6698 xout(screen, sqr.x, sqr.y, sqr.x+sqr.w-1, sqr.y+sqr.h-1, vc(15), vc(0));
6699 }
6700 }
6701 else
6702 {
6703 clear_bitmap(subb);
6704 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
6705
6706 switch(favorite_combo_modes[i])
6707 {
6708 case dm_alias:
6709 draw_combo_alias_thumbnail(subb, &combo_aliases[favorite_combos[i]], 0, 0, 1);
6710 if (ShowFavoriteComboModes)
6711 put_engraving(subb, 0, 0, 0x3E, 1);
6712 break;
6713 case dm_cpool:
6714 {
6715 int32_t cid = -1; int8_t cs = CSet;
6716 combo_pool const& cp = combo_pools[favorite_combos[i]];
6717
6718 if (cp.get_w(cid, cs, 0) && !combobuf[cid].tile)
6719 cid = -1; //no tile to draw
6720 put_combo(subb, 0, 0, cid, cs, 0, 0);
6721 if (ShowFavoriteComboModes)
6722 put_engraving(subb, 0, 0, 0x3D, 1);
6723 break;
6724 }
6725 case dm_auto:
6726 {
6727 int32_t cid = -1; int8_t cs = CSet;
6728 combo_auto const& ca = combo_autos[favorite_combos[i]];
6729
6730 cid = ca.getDisplay();
6731 if (cid == 0)
6732 cid = -1;
6733 put_combo(subb, 0, 0, cid, cs, 0, 0);
6734 if (ShowFavoriteComboModes)
6735 put_engraving(subb, 0, 0, 0x3C, 1);
6736 break;
6737 }
6738 default:
6739 if (repos)
6740 {
6741 combotile_override_x = sqr.x + (sqr.w - 16) / 2;
6742 combotile_override_y = sqr.y + (sqr.h - 16) / 2;
6743 }
6744 put_combo(subb, 0, 0, favorite_combos[i], CSet, Flags & (cFLAGS | cWALK), 0);
6745 if (repos) combotile_override_x = combotile_override_y = -1;
6746 }
6747 stretch_blit(subb, screen, 0, 0, 16, 16, sqr.x, sqr.y, sqr.w, sqr.h);
6748 }
6749 }
6750 }
6751
6752 destroy_bitmap(subb);
6753
6754 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
6755 if(!is_compact)
6756 textprintf_right_ex(screen, get_zc_font(font_lfont_l), favorites_pgleft.x - 2, favorites_pgleft.y, jwin_pal[jcBOXFG], -1, "%d/9", FavoriteComboPage + 1);
6757
6758 draw_text_button(screen, favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-", vc(1), vc(14), 0, true);
6759 draw_text_button(screen, favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->", vc(1), vc(14), 0, true);
6760 draw_text_button(screen,favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6761 draw_text_button(screen,favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X",vc(1),vc(14),0,true);
6762 draw_text_button(screen,favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?",vc(1),vc(14),0,true);
6763 }
6764 break;
6765 case rCOMMANDS:
6766 {
6767 jwin_draw_frame(screen,commands_window.x,commands_window.y,commands_window.w,commands_window.h, FR_WIN);
6768 rectfill(screen,commands_window.x+2,commands_window.y+2,commands_window.x+commands_window.w-3,commands_window.y+commands_window.h-3,jwin_pal[jcBOX]);
6769 jwin_draw_frame(screen,commands_list.x-2,commands_list.y-2,(commands_list.w*commands_list.xscale)+4,(commands_list.h*commands_list.yscale)+4, FR_DEEP);
6770 rectfill(screen,commands_list.x,commands_list.y,commands_list.x+(commands_list.w*commands_list.xscale)-1,commands_list.y+(commands_list.h*commands_list.yscale)-1,jwin_pal[jcBOXFG]);
6771 font=get_custom_font(CFONT_FAVCMD);
6772
6773 for(int32_t cmd=0; cmd<(commands_list.w*commands_list.h); ++cmd)
6774 {
6775 uint hkey = favorite_commands[cmd];
6776 draw_layer_button(screen,
6777 (cmd%commands_list.w)*commands_list.xscale+commands_list.x,
6778 (cmd/commands_list.w)*commands_list.yscale+commands_list.y,
6779 commands_list.xscale,
6780 commands_list.yscale,
6781 get_hotkey_name(hkey),
6782 (selected_hotkey(hkey)?D_SELECTED:0) | (disabled_hotkey(hkey)?D_DISABLED:0));
6783 }
6784
6785 font = get_zc_font(font_lfont_l);
6786 if(commands_txt.x > 0)
6787 {
6788 gui_textout_ln(screen, get_zc_font(font_lfont_l), (ucc*)"Favorite Commands", commands_txt.x, commands_txt.y, jwin_pal[jcBOXFG], -1, 0);
6789 }
6790
6791 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
6792 draw_text_button(screen,commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6793 draw_text_button(screen,commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X",vc(1),vc(14),0,true);
6794 draw_text_button(screen,commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?",vc(1),vc(14),0,true);
6795 }
6796 break;
6797 }
6798 font = tfont;
6799 }
6800
6801 bool pause_refresh = true;
6802 bool is_refreshing = false;
6803 11 void refresh(int32_t flags, bool update)
6804 {
6805
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(pause_refresh) return;
6806 static bool refreshing = false;
6807
6808 int num_screens_to_draw = Map.getViewSize();
6809
6810 bool earlyret = refreshing;
6811 is_refreshing = refreshing = true;
6812 //^ These prevent recursive calls from updating the screen early
6813
6814 bool zoom_delay = (zoomed_minimap && flags != rSCRMAP);
6815 if(zoom_delay)
6816 flags &= ~rSCRMAP;
6817
6818 if(flags&rCLEAR)
6819 {
6820 //magic pink = 0xED
6821 //system black = vc(0)
6822 //Clear a4 menu
6823 // clear_to_color(screen,jwin_pal[jcBOX]);
6824 clear_to_color(screen,0);
6825
6826 //Clears should refresh everything!
6827 flags |= rALL;
6828 }
6829
6830 if(flags&rSCRMAP)
6831 draw_screenunit(rSCRMAP,flags);
6832
6833 if(flags&rMAP)
6834 draw_screenunit(rMAP,flags);
6835
6836 if((flags&rCOMBOS) || (draw_mode == dm_cpool && (flags&rFAVORITES)))
6837 draw_screenunit(rCOMBOS,flags);
6838
6839 if(flags&(rCOMBO|rCOMBOS))
6840 draw_screenunit(rCOMBO,flags);
6841
6842 if(flags&rMENU)
6843 drawpanel();
6844
6845 if(flags&rFAVORITES)
6846 draw_screenunit(rFAVORITES,flags);
6847
6848 if(flags&rCOMMANDS)
6849 draw_screenunit(rCOMMANDS,flags);
6850
6851 FONT* tfont = font;
6852 font = get_custom_font(CFONT_GUI);
6853 jwin_draw_frame(screen,layer_panel.x,layer_panel.y,layer_panel.w,layer_panel.h,FR_DEEP);
6854 rectfill(screen,layer_panel.x,layer_panel.y,layer_panel.x+layer_panel.w-1,layer_panel.y+layer_panel.h-1,jwin_pal[jcBOX]);
6855
6856 for(int32_t i=0; i<=6; ++i)
6857 {
6858 char tbuf[15];
6859
6860 if (i>0 && mapscreen_valid_layers[i - 1] && num_screens_to_draw == 1)
6861 {
6862 if(is_compact)
6863 sprintf(tbuf, "%s%d %d:%02X", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6864 else sprintf(tbuf, "%s%d (%d:%02X)", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6865 }
6866 else
6867 {
6868 sprintf(tbuf, "%s%d", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i);
6869 }
6870
6871 int32_t spacing_offs = is_compact ? 2 : 10;
6872 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
6873 int32_t ry = layer_panel.y;
6874 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
6875 draw_layer_button(screen, rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf, CurrentLayer==i? D_SELECTED : ( i > 0 && !mapscreen_valid_layers[i-1]) ? D_DISABLED : 0);
6876 draw_checkbox(screen,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]!=0);
6877 }
6878
6879 font=tfont;
6880
6881 // } //if(true)
6882 if(zq_showpal)
6883 {
6884 for(int32_t i=0; i<256; i++)
6885 {
6886 rectfill(screen,((i&15)<<2)+256,((i>>4)<<2)+176,((i&15)<<2)+259,((i>>4)<<2)+179,i);
6887 }
6888 }
6889 { //Show top-left info
6890 size_t maxwid = (mapscreen_screenunit_scale*mapscreenbmp->w)-1;
6891 size_t maxhei = (mapscreen_screenunit_scale*mapscreenbmp->w);
6892 set_clip_rect(screen,mapscreen_x,mapscreen_y,mapscreen_x+maxwid-1,mapscreen_y+maxhei-1);
6893 FONT* showfont = get_custom_font(CFONT_INFO);
6894 int showfont_h = text_height(showfont);
6895 int32_t ypos = mapscreen_y;
6896 if(prv_mode)
6897 {
6898 textout_shadowed_ex(screen,showfont,"Preview Mode",0,ypos,vc(15),vc(0),infobg?vc(0):-1);
6899 ypos += showfont_h+1;
6900 if(prv_twon)
6901 {
6902 textprintf_shadowed_ex(screen,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"T Warp=%d tics", Map.get_prvtime());
6903 ypos += showfont_h+1;
6904 }
6905 }
6906 if(ShowFPS)
6907 {
6908 textprintf_shadowed_ex(screen,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"FPS: %3d",lastfps);
6909 ypos += showfont_h+1;
6910 }
6911
6912 if(ShowFFScripts && !prv_mode)
6913 {
6914 word num_ffcs = Map.CurrScr()->numFFC();
6915 for(word i=0; i< num_ffcs; i++)
6916 {
6917 if(ypos+showfont_h-1 > map_page_bar[0].y)
6918 break;
6919 if(Map.CurrScr()->ffcs[i].script && Map.CurrScr()->ffcs[i].data)
6920 {
6921 textout_shadowed_ex(screen, showfont, ffcmap[Map.CurrScr()->ffcs[i].script-1].scriptname.substr(0,300).c_str(),0,ypos,vc(showxypos_ffc==i ? 14 : 15),vc(0),infobg?vc(0):-1);
6922 ypos+=showfont_h+1;
6923 }
6924 }
6925 }
6926 clear_clip_rect(screen);
6927 if(prv_mode)
6928 do_previewtext();
6929 }
6930 // Show Errors & Details
6931 //This includes the presence of: Screen State Carryover, Timed Warp, Maze Path, the 'Sideview Gravity', 'Invisible Hero',
6932 //'Save Screen', 'Continue Here' and 'Treat As..' Screen Flags,
6933 // the String, every Room Type and Catch All, and all four Tile and Side Warps.
6934 if(!prv_mode && ShowInfo)
6935 {
6936 int32_t i=0;
6937 char buf[2048];
6938
6939 // Start with general information
6940 if(Map.CurrScr()->flags3&fINVISHERO)
6941 {
6942 sprintf(buf,"Invisible Hero");
6943 show_screen_error(buf,i++,vc(15));
6944 }
6945
6946 if(Map.getLayerTargetMap() > 0)
6947 {
6948 Map.setlayertarget(); //Now the text does not carry over when changing maps, but shifting back, it does not **re-appear** until you change screens.
6949 //It was also required to set some updates in onDecMap and onIncMap. #
6950 //This fixes Screen Info not displaying properly when changing maps. -Z
6951 //Needed to refresh the screen info. -Z ( 26th March, 2019 )
6952 int32_t m = Map.getLayerTargetMultiple();
6953 sprintf(buf,"Used as a layer by screen %d:%02X",Map.getLayerTargetMap(),Map.getLayerTargetScr());
6954 char buf2[24];
6955
6956 if(m>0)
6957 {
6958 sprintf(buf2," and %d other%s",m,m>1?"s":"");
6959 strcat(buf,buf2);
6960 }
6961
6962 show_screen_error(buf,i++,vc(15));
6963 }
6964
6965 if(Map.CurrScr()->nextmap)
6966 {
6967 sprintf(buf,"Screen State carries over to %d:%02X",Map.CurrScr()->nextmap,Map.CurrScr()->nextscr);
6968 show_screen_error(buf,i++,vc(15));
6969 }
6970
6971 if(Map.CurrScr()->timedwarptics)
6972 {
6973 sprintf(buf,"%s%sTimed Warp: %s",(Map.CurrScr()->flags4&fTIMEDDIRECT)?"Direct ":"",(Map.CurrScr()->flags5&fRANDOMTIMEDWARP)?"Random ":"",ticksstr(Map.CurrScr()->timedwarptics));
6974 show_screen_error(buf,i++,vc(15));
6975 }
6976
6977 if(Map.CurrScr()->flags&fMAZE)
6978 {
6979 sprintf(buf,"Maze Path: %s (Exit %s)",pathstr(Map.CurrScr()->path),mazedirstr[Map.CurrScr()->exitdir]);
6980 show_screen_error(buf,i++,vc(15));
6981 }
6982
6983 bool continuescreen = false, savecombo = false;
6984
6985 if(Map.CurrScr()->flags4&fAUTOSAVE)
6986 {
6987 sprintf(buf,"Automatic Save%s Screen", (Map.CurrScr()->flags6&fCONTINUEHERE) ? "-Continue":"");
6988 show_screen_error(buf,i++,vc(15));
6989 continuescreen = ((Map.CurrScr()->flags6&fCONTINUEHERE)!=0);
6990 savecombo = true;
6991 }
6992 else if(Map.CurrScr()->flags6&fCONTINUEHERE)
6993 {
6994 sprintf(buf,"Continue Screen");
6995 show_screen_error(buf,i++,vc(15));
6996 continuescreen = true;
6997 }
6998
6999 if(isSideViewGravity())
7000 {
7001 sprintf(buf,"Sideview Gravity");
7002 show_screen_error(buf,i++,vc(15));
7003 }
7004
7005 if(Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM))
7006 {
7007 sprintf(buf,"Treat As %s%s Screen", (Map.CurrScr()->flags6&fCAVEROOM) ? "Interior":"NES Dungeon",
7008 (Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM)) == (fCAVEROOM|fDUNGEONROOM) ? " or NES Dungeon":"");
7009 show_screen_error(buf,i++,vc(15));
7010 }
7011
7012 if(Map.CurrScr()->oceansfx != 0)
7013 {
7014 sprintf(buf,"Ambient Sound: %s",sfx_string[Map.CurrScr()->oceansfx]);
7015 show_screen_error(buf,i++,vc(15));
7016 }
7017
7018 if(Map.CurrScr()->bosssfx != 0)
7019 {
7020 sprintf(buf,"Boss Roar Sound: %s",sfx_string[Map.CurrScr()->bosssfx]);
7021 show_screen_error(buf,i++,vc(15));
7022 }
7023
7024 if(Map.CurrScr()->str)
7025 {
7026 strncpy(buf,MsgString(Map.CurrScr()->str, true, false),72);
7027 buf[72] = '\0';
7028 char shortbuf[72];
7029 strip_extra_spaces(buf);
7030 shorten_string(shortbuf, buf, get_zc_font(font_lfont_l), 72, 280);
7031 sprintf(buf,"String %s",shortbuf);
7032 show_screen_error(buf,i++,vc(15));
7033 }
7034
7035 if((Map.CurrScr()->flags&fWHISTLE) || (Map.CurrScr()->flags7&fWHISTLEWATER))
7036 {
7037 sprintf(buf,"Whistle ->%s%s%s",(Map.CurrScr()->flags&fWHISTLE)?" Stairs":"",
7038 (Map.CurrScr()->flags&fWHISTLE && Map.CurrScr()->flags7&fWHISTLEWATER)?", ":"",
7039 (Map.CurrScr()->flags7&fWHISTLEWATER)?"Dry Lake":"");
7040 show_screen_error(buf,i++,vc(15));
7041 }
7042
7043 switch(Map.CurrScr()->room)
7044 {
7045 case rSP_ITEM:
7046 sprintf(buf,"Special Item is %s",item_string[Map.CurrScr()->catchall]);
7047 show_screen_error(buf,i++, vc(15));
7048 break;
7049
7050 case rINFO:
7051 {
7052 int32_t shop = Map.CurrScr()->catchall;
7053 sprintf(buf,"Pay For Info: -%d, -%d, -%d",
7054 QMisc.info[shop].price[0],QMisc.info[shop].price[1],QMisc.info[shop].price[2]);
7055 show_screen_error(buf,i++, vc(15));
7056 }
7057 break;
7058
7059 case rMONEY:
7060 sprintf(buf,"Secret Money: %d Rupees",Map.CurrScr()->catchall);
7061 show_screen_error(buf,i++, vc(15));
7062 break;
7063
7064 case rGAMBLE:
7065 show_screen_error("Gamble Room",i++, vc(15));
7066 break;
7067
7068 case rREPAIR:
7069 sprintf(buf,"Door Repair: -%d Rupees",Map.CurrScr()->catchall);
7070 show_screen_error(buf,i++, vc(15));
7071 break;
7072
7073 case rRP_HC:
7074 sprintf(buf,"Take %s or %s", item_string[iRPotion], item_string[iHeartC]);
7075 show_screen_error(buf,i++, vc(15));
7076 break;
7077
7078 case rGRUMBLE:
7079 show_screen_error("Feed the Goriya",i++, vc(15));
7080 break;
7081
7082 case rTRIFORCE:
7083 show_screen_error("Triforce Check",i++, vc(15));
7084 break;
7085
7086 case rP_SHOP:
7087 case rSHOP:
7088 {
7089 int32_t shop = Map.CurrScr()->catchall;
7090 sprintf(buf,"%sShop: ",
7091 Map.CurrScr()->room==rP_SHOP ? "Potion ":"");
7092
7093 for(int32_t j=0; j<3; j++) if(QMisc.shop[shop].item[j]>0) // Print the 3 items and prices
7094 {
7095 strcat(buf,item_string[QMisc.shop[shop].item[j]]);
7096 strcat(buf,":");
7097 char pricebuf[8];
7098 sprintf(pricebuf,"%d",QMisc.shop[shop].price[j]);
7099 strcat(buf,pricebuf);
7100
7101 if(j<2 && QMisc.shop[shop].item[j+1]>0) strcat(buf,", ");
7102 }
7103
7104 show_screen_error(buf,i++, vc(15));
7105 }
7106 break;
7107
7108 case rBOTTLESHOP:
7109 {
7110 int32_t shop = Map.CurrScr()->catchall;
7111 sprintf(buf,"Bottle Shop: ");
7112
7113 for(int32_t j=0; j<3; j++) if(QMisc.bottle_shop_types[shop].fill[j]>0) // Print the 3 fills and prices
7114 {
7115 strcat(buf,QMisc.bottle_types[QMisc.bottle_shop_types[shop].fill[j]-1].name);
7116 strcat(buf,":");
7117 char pricebuf[8];
7118 sprintf(pricebuf,"%d",QMisc.bottle_shop_types[shop].price[j]);
7119 strcat(buf,pricebuf);
7120
7121 if(j<2 && QMisc.bottle_shop_types[shop].fill[j+1]>0) strcat(buf,", ");
7122 }
7123
7124 show_screen_error(buf,i++, vc(15));
7125 }
7126 break;
7127
7128 case rTAKEONE:
7129 {
7130 int32_t shop = Map.CurrScr()->catchall;
7131 sprintf(buf,"Take Only One: %s%s%s%s%s",
7132 QMisc.shop[shop].item[0]<1?"":item_string[QMisc.shop[shop].item[0]],QMisc.shop[shop].item[0]>0?", ":"",
7133 QMisc.shop[shop].item[1]<1?"":item_string[QMisc.shop[shop].item[1]],(QMisc.shop[shop].item[1]>0&&QMisc.shop[shop].item[2]>0)?", ":"",
7134 QMisc.shop[shop].item[2]<1?"":item_string[QMisc.shop[shop].item[2]]);
7135 show_screen_error(buf,i++, vc(15));
7136 }
7137 break;
7138
7139 case rBOMBS:
7140 sprintf(buf,"More Bombs: -%d Rupees",Map.CurrScr()->catchall);
7141 show_screen_error(buf,i++, vc(15));
7142 break;
7143
7144 case rARROWS:
7145 sprintf(buf,"More Arrows: -%d Rupees",Map.CurrScr()->catchall);
7146 show_screen_error(buf,i++, vc(15));
7147 break;
7148
7149 case rSWINDLE:
7150 sprintf(buf,"Leave Life or %d Rupees",Map.CurrScr()->catchall);
7151 show_screen_error(buf,i++, vc(15));
7152 break;
7153
7154 case r10RUPIES:
7155 show_screen_error("10 Rupees",i++, vc(15));
7156 break;
7157
7158 case rGANON:
7159 show_screen_error("Ganon Room",i++, vc(15));
7160 break;
7161
7162 case rZELDA:
7163 show_screen_error("Zelda Room",i++, vc(15));
7164 break;
7165
7166 case rMUPGRADE:
7167 show_screen_error("1/2 Magic Upgrade",i++, vc(15));
7168 break;
7169
7170 case rLEARNSLASH:
7171 show_screen_error("Learn Slash",i++, vc(15));
7172 break;
7173
7174 case rWARP:
7175 sprintf(buf,"3-Stair Warp: Warp Ring %d",Map.CurrScr()->catchall);
7176 show_screen_error(buf,i++, vc(15));
7177 break;
7178 }
7179
7180 bool undercombo = false, warpa = false, warpb = false, warpc = false, warpd = false, warpr = false;
7181
7182 word num_ffcs = Map.CurrScr()->numFFC();
7183 for(int32_t c=0; c<176+128+1+num_ffcs; ++c)
7184 {
7185 // Checks both combos, secret combos, undercombos and FFCs
7186 //Fixme:
7187 int32_t ctype =
7188 combobuf[vbound(
7189 (c>=305 ? Map.CurrScr()->ffcs[c-305].data :
7190 c>=304 ? Map.CurrScr()->undercombo :
7191 c>=176 ? Map.CurrScr()->secretcombo[c-176] :
7192 !Map.CurrScr()->valid ? 0 : // Sanity check: does room combo data exist?
7193 Map.CurrScr()->data[c]
7194 ), 0, MAXCOMBOS-1)].type;
7195
7196 if(!undercombo && integrityBoolUnderCombo(Map.CurrScr(),ctype))
7197 {
7198 undercombo = true;
7199 show_screen_error("Under Combo is combo 0",i++, vc(7));
7200 }
7201
7202 // Tile Warp types
7203 switch(ctype)
7204 {
7205 case cSAVE:
7206 case cSAVE2:
7207 if(!savecombo)
7208 {
7209 savecombo = true;
7210
7211 if(integrityBoolSaveCombo(Map.CurrScr(),ctype))
7212 show_screen_error("Save Screen",i++, vc(15));
7213 else
7214 show_screen_error("Save-Continue Screen",i++, vc(15));
7215 }
7216
7217 break;
7218
7219 case cSTAIRR:
7220 case cPITR:
7221 case cSWARPR:
7222 if(!warpr && (Map.CurrScr()->tilewarptype[0]==wtCAVE || Map.CurrScr()->tilewarptype[1]==wtCAVE ||
7223 Map.CurrScr()->tilewarptype[2]==wtCAVE || Map.CurrScr()->tilewarptype[3]==wtCAVE))
7224 {
7225 warpr = true;
7226 show_screen_error("Random Tile Warp contains Cave/Item Cellar",i++, vc(7));
7227 }
7228
7229 break;
7230
7231 case cCAVED:
7232 case cPITD:
7233 case cSTAIRD:
7234 case cCAVE2D:
7235 case cSWIMWARPD:
7236 case cDIVEWARPD:
7237 case cSWARPD:
7238 if(!warpd)
7239 {
7240 warpd = true;
7241 tile_warp_notification(3,buf);
7242 show_screen_error(buf,i++, vc(15));
7243 }
7244
7245 break;
7246
7247 case cCAVEC:
7248 case cPITC:
7249 case cSTAIRC:
7250 case cCAVE2C:
7251 case cSWIMWARPC:
7252 case cDIVEWARPC:
7253 case cSWARPC:
7254 if(!warpc)
7255 {
7256 warpc = true;
7257 tile_warp_notification(2,buf);
7258 show_screen_error(buf,i++, vc(15));
7259 }
7260
7261 break;
7262
7263 case cCAVEB:
7264 case cPITB:
7265 case cSTAIRB:
7266 case cCAVE2B:
7267 case cSWIMWARPB:
7268 case cDIVEWARPB:
7269 case cSWARPB:
7270 if(!warpb)
7271 {
7272 warpb = true;
7273 tile_warp_notification(1,buf);
7274 show_screen_error(buf,i++, vc(15));
7275 }
7276
7277 break;
7278
7279 case cCAVE:
7280 case cPIT:
7281 case cSTAIR:
7282 case cCAVE2:
7283 case cSWIMWARP:
7284 case cDIVEWARP:
7285 case cSWARPA:
7286 if(!warpa)
7287 {
7288 warpa = true;
7289 tile_warp_notification(0,buf);
7290 show_screen_error(buf,i++, vc(15));
7291 }
7292
7293 break;
7294 }
7295 }
7296
7297 int32_t sidewarpnotify = 0;
7298
7299 if(Map.CurrScr()->flags2&wfUP)
7300 {
7301 side_warp_notification(Map.CurrScr()->sidewarpindex&3,0,buf);
7302 show_screen_error(buf,i++, vc(15));
7303 sidewarpnotify|=(1<<(Map.CurrScr()->sidewarpindex&3));
7304 }
7305
7306 if(Map.CurrScr()->flags2&wfDOWN)
7307 {
7308 side_warp_notification((Map.CurrScr()->sidewarpindex>>2)&3,1,buf);
7309 show_screen_error(buf,i++, vc(15));
7310 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>2)&3));
7311 }
7312
7313 if(Map.CurrScr()->flags2&wfLEFT)
7314 {
7315 side_warp_notification((Map.CurrScr()->sidewarpindex>>4)&3,2,buf);
7316 show_screen_error(buf,i++, vc(15));
7317 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>4)&3));
7318 }
7319
7320 if(Map.CurrScr()->flags2&wfRIGHT)
7321 {
7322 side_warp_notification((Map.CurrScr()->sidewarpindex>>6)&3,3,buf);
7323 show_screen_error(buf,i++, vc(15));
7324 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>6)&3));
7325 }
7326
7327 if(!(sidewarpnotify&1) && Map.CurrScr()->timedwarptics)
7328 {
7329 side_warp_notification(0,4,buf); // Timed Warp
7330 show_screen_error(buf,i++, vc(15));
7331 }
7332
7333 // Now for errors
7334 if((Map.CurrScr()->flags4&fSAVEROOM) && !savecombo) show_screen_error("Save Point->Continue Here, but no Save Point combo?",i++, vc(14));
7335
7336 if(integrityBoolEnemiesItem(Map.CurrScr())) show_screen_error("Enemies->Item, but no enemies",i++, vc(7));
7337
7338 if(integrityBoolEnemiesSecret(Map.CurrScr())) show_screen_error("Enemies->Secret, but no enemies",i++, vc(7));
7339
7340 if(integrityBoolGuyNoString(Map.CurrScr())) show_screen_error("Non-Fairy Guy, but String is (none)",i++, vc(14));
7341
7342 if(integrityBoolRoomNoGuy(Map.CurrScr())) show_screen_error("Guy is (none)",i++, vc(14));
7343
7344 if(integrityBoolRoomNoString(Map.CurrScr())) show_screen_error("String is (none)",i++, vc(14));
7345
7346 if(integrityBoolRoomNoGuyNoString(Map.CurrScr())) show_screen_error("Guy and String are (none)",i++, vc(14));
7347 }
7348
7349 if(zoom_delay)
7350 draw_screenunit(rSCRMAP,flags);
7351
7352 if(earlyret)
7353 return;
7354
7355 //Draw the Main Menu
7356 rectfill(screen,mainbar.x,mainbar.y,mainbar.x+mainbar.w-1,mainbar.y+mainbar.h-1,jwin_pal[jcBOX]);
7357 jwin_draw_frame(screen,mainbar.x,mainbar.y,mainbar.w,mainbar.h,FR_WIN);
7358
7359 FONT* oldfont = font;
7360 font = get_custom_font(CFONT_GUI);
7361
7362 //Drawmode button
7363 draw_text_button(screen,drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode],vc(1),vc(14),0,true);
7364 //Compact button
7365 draw_text_button(screen,compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact", vc(1),vc(14),0,true);
7366 //Zoom buttons
7367 zoom_in_btn_disabled = num_screens_to_draw == 1;
7368 zoom_out_btn_disabled = num_screens_to_draw == mapscreen_num_screens_to_draw_max;
7369 draw_text_button(screen,zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+", vc(1),vc(14),zoom_in_btn_disabled ? D_DISABLED : 0,true);
7370 draw_text_button(screen,zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-", vc(1),vc(14),zoom_out_btn_disabled ? D_DISABLED : 0,true);
7371
7372 font = oldfont;
7373
7374 d_nbmenu_proc(MSG_DRAW, &dialogs[0], 0);
7375
7376 ComboBrushPause=0;
7377
7378 if(update)
7379 custom_vsync();
7380 is_refreshing = refreshing = false;
7381 11 }
7382
7383 12 static int minimap_tooltip_id = ttip_register_id();
7384
7385 void select_scr()
7386 {
7387 if(Map.getCurrMap()>=Map.getMapCount())
7388 return;
7389
7390 int32_t tempcb=ComboBrush;
7391 ComboBrush=0;
7392
7393 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
7394
7395 auto prev_cursor = Map.getCursor();
7396 Map.ConfigureCursorHistory(false);
7397
7398 //scooby
7399 while(gui_mouse_b())
7400 {
7401 int32_t x=gui_mouse_x();
7402 int32_t y=gui_mouse_y();
7403
7404 int32_t ind = real_mini.rectind(x,y);
7405
7406 if(ind>=MAPSCRS)
7407 ind-=16;
7408
7409 if(ind > -1 && ind != Map.getCurrScr())
7410 {
7411 Map.setCurrScr(ind);
7412 }
7413
7414 custom_vsync();
7415 refresh(rALL);
7416 }
7417
7418 ComboBrush=tempcb;
7419
7420 Map.ConfigureCursorHistory(true);
7421 if (prev_cursor != Map.getCursor())
7422 Map.pushCursorToHistory(prev_cursor);
7423 }
7424
7425 bool select_favorite()
7426 {
7427 int32_t tempcb=ComboBrush;
7428 ComboBrush=0;
7429 bool valid=false;
7430
7431 while(gui_mouse_b())
7432 {
7433 valid=false;
7434 int32_t x=gui_mouse_x();
7435
7436 if(x<favorites_list.x)
7437 x=favorites_list.x;
7438
7439 if(x>favorites_list.x+(favorites_list.w*favorites_list.xscale)-1)
7440 x=favorites_list.x+(favorites_list.w*favorites_list.xscale)-1;
7441
7442 int32_t y=gui_mouse_y();
7443
7444 if(y<favorites_list.y)
7445 y=favorites_list.y;
7446
7447 if(y>favorites_list.y+(favorites_list.h*favorites_list.yscale)-1)
7448 y=favorites_list.y+(favorites_list.h*favorites_list.yscale)-1;
7449
7450 int32_t tempc=(((y-favorites_list.y)/favorites_list.yscale)*FAVORITECOMBO_PER_ROW)+((x-favorites_list.x)/favorites_list.xscale) + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
7451
7452 if(tempc >= MAXFAVORITECOMBOS)
7453 {
7454 //Nothing, invalid
7455 }
7456 else
7457 {
7458 if(favorite_combos[tempc]!=-1)
7459 {
7460 switch(favorite_combo_modes[tempc])
7461 {
7462 case dm_alias:
7463 draw_mode = dm_alias;
7464 combo_apos = favorite_combos[tempc];
7465 break;
7466 case dm_cpool:
7467 draw_mode = dm_cpool;
7468 combo_pool_pos = favorite_combos[tempc];
7469 break;
7470 case dm_auto:
7471 draw_mode = dm_auto;
7472 combo_auto_pos = favorite_combos[tempc];
7473 break;
7474 default:
7475 draw_mode = dm_normal;
7476 Combo = favorite_combos[tempc];
7477 }
7478 if(AutoBrush)
7479 BrushWidth = BrushHeight = 1;
7480 valid=true;
7481 fix_drawing_mode_menu();
7482 }
7483 }
7484
7485 custom_vsync();
7486 refresh(rALL);
7487 }
7488
7489 ComboBrush=tempcb;
7490 return valid;
7491 }
7492
7493 void select_combo(int32_t clist)
7494 {
7495 current_combolist=clist;
7496 int32_t tempcb=ComboBrush;
7497 ComboBrush=0;
7498
7499 int autobrush_cx = -1, autobrush_cy = -1;
7500 int autobrush_first = First[current_combolist];
7501 auto& curlist = combolist[current_combolist];
7502 AutoBrushRevert = (key[KEY_ALT]||key[KEY_ALTGR]);
7503 while(gui_mouse_b())
7504 {
7505 int32_t x=gui_mouse_x();
7506
7507 if(x<curlist.x)
7508 x=curlist.x;
7509
7510 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7511 x=curlist.x+(curlist.w*curlist.xscale)-1;
7512
7513 int32_t y=gui_mouse_y();
7514
7515 if(y<curlist.y)
7516 y=curlist.y;
7517
7518 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7519 y=curlist.y+(curlist.h*curlist.yscale)-1;
7520
7521 int cx = ((x-curlist.x)/curlist.xscale), cy = ((y-curlist.y)/curlist.yscale);
7522 if(AutoBrush)
7523 {
7524 if(autobrush_cx < 0)
7525 {
7526 autobrush_cx = cx;
7527 autobrush_cy = cy;
7528 }
7529 BrushWidth = vbound(abs(autobrush_cx-cx)+1,1,16);
7530 BrushHeight = vbound(abs(autobrush_cy-cy)+1,1,11);
7531 cx = std::min(autobrush_cx,cx);
7532 cy = std::min(autobrush_cy,cy);
7533 }
7534 Combo=(cy*curlist.w)+cx+First[current_combolist];
7535 custom_vsync();
7536 refresh(rALL);
7537 if(AutoBrush) //Prevent any scrolling
7538 First[current_combolist] = autobrush_first;
7539 }
7540 if(key[KEY_ALT]||key[KEY_ALTGR])
7541 AutoBrushRevert = true;
7542 position_mouse_z(0);
7543 ComboBrush=tempcb;
7544 }
7545
7546 void select_comboa(int32_t clist)
7547 {
7548 current_comboalist=clist;
7549 int32_t tempcb=ComboBrush;
7550 ComboBrush=0;
7551 alias_cset_mod=0;
7552
7553 auto& curlist = comboaliaslist[current_comboalist];
7554 while(gui_mouse_b())
7555 {
7556 int32_t x=gui_mouse_x();
7557
7558 if(x<curlist.x)
7559 x=curlist.x;
7560
7561 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7562 x=curlist.x+(curlist.w*curlist.xscale)-1;
7563
7564 int32_t y=gui_mouse_y();
7565
7566 if(y<curlist.y)
7567 y=curlist.y;
7568
7569 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7570 y=curlist.y+(curlist.h*curlist.yscale)-1;
7571
7572 combo_apos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_alistpos[current_comboalist];
7573 custom_vsync();
7574 refresh(rALL);
7575 }
7576
7577 ComboBrush=tempcb;
7578 }
7579
7580 void select_combop(int32_t clist)
7581 {
7582 current_cpoollist=clist;
7583 int32_t tempcb=ComboBrush;
7584 ComboBrush=0;
7585
7586 auto& curlist = comboaliaslist[current_cpoollist];
7587 while(gui_mouse_b())
7588 {
7589 int32_t x=gui_mouse_x();
7590
7591 if(x<curlist.x) x=curlist.x;
7592
7593 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7594 x=curlist.x+(curlist.w*curlist.xscale)-1;
7595
7596 int32_t y=gui_mouse_y();
7597
7598 if(y<curlist.y) y=curlist.y;
7599
7600 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7601 y=curlist.y+(curlist.h*curlist.yscale)-1;
7602
7603 combo_pool_pos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_pool_listpos[current_cpoollist];
7604 custom_vsync();
7605 refresh(rALL);
7606 }
7607
7608 ComboBrush=tempcb;
7609 }
7610
7611 void select_autocombo(int32_t clist)
7612 {
7613 current_cautolist = clist;
7614 int32_t tempcb = ComboBrush;
7615 ComboBrush = 0;
7616
7617 auto& curlist = comboaliaslist[current_cautolist];
7618 while (gui_mouse_b())
7619 {
7620 int32_t x = gui_mouse_x();
7621
7622 if (x < curlist.x) x = curlist.x;
7623
7624 if (x > curlist.x + (curlist.w * curlist.xscale) - 1)
7625 x = curlist.x + (curlist.w * curlist.xscale) - 1;
7626
7627 int32_t y = gui_mouse_y();
7628
7629 if (y < curlist.y) y = curlist.y;
7630
7631 if (y > curlist.y + (curlist.h * curlist.yscale) - 1)
7632 y = curlist.y + (curlist.h * curlist.yscale) - 1;
7633
7634 combo_auto_pos = (((y - curlist.y) / curlist.yscale) * curlist.w) + ((x - curlist.x) / curlist.xscale) + combo_auto_listpos[current_cautolist];
7635 cauto_height = combo_autos[combo_auto_pos].getArg() + 1;
7636 custom_vsync();
7637 refresh(rALL);
7638 }
7639
7640 ComboBrush = tempcb;
7641 }
7642
7643 void update_combobrush()
7644 {
7645 clear_bitmap(brushbmp);
7646
7647 if(draw_mode==dm_alias)
7648 {
7649 //int32_t count=(combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*(comboa_lmasktotal(combo_aliases[combo_apos].layermask));
7650 for(int32_t z=0; z<=comboa_lmasktotal(combo_aliases[combo_apos].layermask); z++)
7651 {
7652 for(int32_t y=0; y<=combo_aliases[combo_apos].height; y++)
7653 {
7654 for(int32_t x=0; x<=combo_aliases[combo_apos].width; x++)
7655 {
7656 int32_t position = ((y*(combo_aliases[combo_apos].width+1))+x)+((combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*z);
7657
7658 if(combo_aliases[combo_apos].combos[position])
7659 {
7660 if(z==0)
7661 {
7662 putcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7663 }
7664 else
7665 {
7666 overcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7667 }
7668 }
7669 }
7670 }
7671 }
7672
7673 int xoff = 6, yoff = 6;
7674 if(FloatBrush) // Offset the floating pixels, so the 'x' appears centered on the combo still -Em
7675 {
7676 xoff += 2;
7677 yoff += 2;
7678 }
7679 if(alias_origin & 1) // Right-align
7680 xoff += combo_aliases[combo_apos].width*16;
7681 if(alias_origin & 2) // Bottom-align
7682 yoff += combo_aliases[combo_apos].height*16;
7683
7684 textprintf_shadowed_ex(brushbmp, get_zc_font(font_sfont), xoff, yoff, vc(15), vc(0), -1, "x");
7685 }
7686 else if(draw_mode != dm_cpool)
7687 {
7688 int32_t cid = combobrushoverride > -1 ? combobrushoverride : Combo;
7689 int32_t c = 0;
7690
7691 for(int32_t i=0; i<256; i++)
7692 {
7693 if(unsigned(cid+c) >= MAXCOMBOS) break;
7694 if(((i%COMBOS_PER_ROW)<BrushWidth)&&((i/COMBOS_PER_ROW)<BrushHeight))
7695 {
7696 put_combo(brushbmp,(i%COMBOS_PER_ROW)<<4,(i/COMBOS_PER_ROW)<<4,cid+c,CSet,Flags&(cFLAGS|cWALK),0);
7697 }
7698
7699 if(((cid+c)&3)==3)
7700 c+=48;
7701
7702 ++c;
7703
7704 if((i%COMBOS_PER_ROW)==(COMBOS_PER_ROW-1))
7705 c-=256;
7706 }
7707 }
7708 }
7709
7710 byte relational_source_grid[256]=
7711 {
7712 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7713 16, 16, 17, 17, 18, 18, 19, 19, 16, 16, 17, 17, 18, 18, 19, 19,
7714 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23,
7715 24, 24, 24, 24, 25, 25, 25, 25, 24, 24, 24, 24, 25, 25, 25, 25,
7716 26, 27, 26, 27, 26, 27, 26, 27, 28, 29, 28, 29, 28, 29, 28, 29,
7717 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
7718 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32,
7719 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
7720 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37,
7721 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39,
7722 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
7723 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
7724 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43,
7725 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
7726 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
7727 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46
7728 };
7729
7730 static void draw_autocombo(ComboPosition combo_pos, bool rclick, bool pressframe = false)
7731 {
7732 combo_auto &ca = combo_autos[combo_auto_pos];
7733 int screen = Map.getScreenForPosition(combo_pos);
7734 int pos = combo_pos.truncate();
7735
7736 if (ca.valid())
7737 {
7738 switch (ca.getType())
7739 {
7740 case AUTOCOMBO_BASIC:
7741 {
7742 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7743 if (rclick)
7744 ap.erase(screen, pos);
7745 else
7746 ap.execute(screen, pos);
7747 break;
7748 }
7749 case AUTOCOMBO_Z1:
7750 {
7751 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7752 if (rclick)
7753 ap.erase(screen, pos);
7754 else
7755 ap.execute(screen, pos);
7756 break;
7757 }
7758 case AUTOCOMBO_FENCE:
7759 {
7760 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7761 if (rclick)
7762 ap.erase(screen, pos);
7763 else
7764 ap.execute(screen, pos);
7765 break;
7766 }
7767 case AUTOCOMBO_Z4:
7768 {
7769 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7770 if (rclick)
7771 ap.erase(screen, pos);
7772 else
7773 ap.execute(screen, pos);
7774 break;
7775 }
7776 case AUTOCOMBO_RELATIONAL:
7777 {
7778 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7779 if (rclick)
7780 ap.erase(screen, pos);
7781 else
7782 ap.execute(screen, pos);
7783 break;
7784 }
7785 case AUTOCOMBO_DGNCARVE:
7786 {
7787 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7788 if (rclick)
7789 ap.erase(screen, pos);
7790 else
7791 ap.execute(screen, pos);
7792 break;
7793 }
7794 case AUTOCOMBO_DOR:
7795 {
7796 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7797 if (rclick)
7798 ap.erase(screen, pos);
7799 else
7800 ap.execute(screen, pos);
7801 break;
7802 }
7803 case AUTOCOMBO_TILING:
7804 {
7805 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7806 {
7807 int32_t x = (screen % 16) * 16 + (pos % 16);
7808 int32_t y = (screen / 16) * 11 + (pos / 16);
7809 byte w = (ca.getArg() & 0xF) + 1;
7810 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7811 ca.setOffsets(x % w, y % h);
7812 }
7813 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7814 if (rclick)
7815 ap.erase(screen, pos);
7816 else
7817 ap.execute(screen, pos);
7818 break;
7819 }
7820 case AUTOCOMBO_REPLACE:
7821 {
7822 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7823 if (rclick)
7824 ap.erase(screen, pos);
7825 else
7826 ap.execute(screen, pos);
7827 break;
7828 }
7829 case AUTOCOMBO_DENSEFOREST:
7830 {
7831 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7832 {
7833 int32_t x = (screen % 16) * 16 + (pos % 16);
7834 int32_t y = (screen / 16) * 11 + (pos / 16);
7835 ca.setOffsets(x % 2, y % 2);
7836 }
7837 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7838 if (rclick)
7839 ap.erase(screen, pos);
7840 else
7841 ap.execute(screen, pos);
7842 break;
7843 }
7844 case AUTOCOMBO_EXTEND:
7845 {
7846 if (CHECK_CTRL_CMD)
7847 break;
7848 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7849 if (rclick)
7850 ap.erase(screen, pos);
7851 else
7852 ap.execute(screen, pos);
7853 break;
7854 }
7855 }
7856 }
7857 else
7858 {
7859 ca.updateValid();
7860 if(!ca.valid())
7861 InfoDialog("Notice", "The autocombo you're trying to use is invalid. Reason:"
7862 + ca.getInvalidReason()).show();
7863 }
7864 }
7865
7866 static void draw_autocombo_command(ComboPosition combo_pos, int32_t cmd = 0, int32_t arg = 0)
7867 {
7868 combo_auto ca = combo_autos[combo_auto_pos];
7869 int screen = Map.getScreenForPosition(combo_pos);
7870 int pos = combo_pos.truncate();
7871
7872 if (ca.valid())
7873 {
7874 switch (ca.getType())
7875 {
7876 case AUTOCOMBO_FENCE:
7877 {
7878 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7879 ap.flip_all_connected(screen, pos, 2048);
7880 break;
7881 }
7882 case AUTOCOMBO_Z4:
7883 {
7884 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7885 switch (cmd)
7886 {
7887 case 0: // Flip
7888 ap.flip_all_connected(screen, pos, 2048);
7889 break;
7890 case 1: // Grow
7891 ap.resize_connected(screen, pos, 2048, vbound(arg, 1, 9));
7892 break;
7893 }
7894 }
7895 }
7896 }
7897 }
7898
7899 static int32_t get_autocombo_floating_cid(ComboPosition combo_pos, bool clicked)
7900 {
7901 combo_auto& ca = combo_autos[combo_auto_pos];
7902 int screen = Map.getScreenForPosition(combo_pos);
7903 int pos = combo_pos.truncate();
7904 int cid = 0;
7905
7906 if (ca.valid() && Map.isValidPosition(mouse_combo_pos))
7907 {
7908 switch (ca.getType())
7909 {
7910 case AUTOCOMBO_BASIC:
7911 {
7912 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7913 cid = ap.get_floating_cid(screen, pos);
7914 break;
7915 }
7916
7917 case AUTOCOMBO_Z1:
7918 {
7919 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7920 cid = ap.get_floating_cid(screen, pos);
7921 break;
7922 }
7923 case AUTOCOMBO_FENCE:
7924 {
7925 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7926 cid = ap.get_floating_cid(screen, pos);
7927 break;
7928 }
7929 case AUTOCOMBO_Z4:
7930 {
7931 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7932 cid = ap.get_floating_cid(screen, pos);
7933 break;
7934 }
7935 case AUTOCOMBO_RELATIONAL:
7936 {
7937 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7938 cid = ap.get_floating_cid(screen, pos);
7939 break;
7940 }
7941 case AUTOCOMBO_DGNCARVE:
7942 {
7943 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7944 cid = ap.get_floating_cid(screen, pos);
7945 break;
7946 }
7947 case AUTOCOMBO_DOR:
7948 {
7949 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7950 cid = ap.get_floating_cid(screen, pos);
7951 break;
7952 }
7953 case AUTOCOMBO_TILING:
7954 {
7955 std::pair<byte, byte> offs = ca.getOffsets();
7956 if (!clicked && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7957 {
7958 int32_t x = (screen % 16) * 16 + (pos % 16);
7959 int32_t y = (screen / 16) * 11 + (pos / 16);
7960 byte w = (ca.getArg() & 0xF) + 1;
7961 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7962 offs.first = (x % w);
7963 offs.second = (y % h);
7964 }
7965 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7966 cid = ap.get_floating_cid(screen, pos);
7967 break;
7968 }
7969 case AUTOCOMBO_REPLACE:
7970 {
7971 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7972 cid = ap.get_floating_cid(screen, pos);
7973 break;
7974 }
7975 case AUTOCOMBO_DENSEFOREST:
7976 {
7977 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7978 cid = ap.get_floating_cid(screen, pos);
7979 break;
7980 }
7981 case AUTOCOMBO_EXTEND:
7982 {
7983 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7984 cid = ap.get_floating_cid(screen, pos);
7985 break;
7986 }
7987 }
7988 }
7989 return cid;
7990 }
7991
7992 void change_autocombo_height(int32_t change)
7993 {
7994 bool can_change = false;
7995 if (draw_mode == dm_auto)
7996 {
7997 combo_auto ca = combo_autos[combo_auto_pos];
7998 switch (ca.getType())
7999 {
8000 case AUTOCOMBO_Z4:
8001 can_change = true;
8002 [[fallthrough]];
8003 case AUTOCOMBO_DOR:
8004 break;
8005 default:
8006 return;
8007 }
8008 }
8009 else
8010 return;
8011
8012 int32_t x = gui_mouse_x();
8013 int32_t y = gui_mouse_y();
8014 double startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
8015 double starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
8016 int32_t startxint = mapscreen_x + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
8017 int32_t startyint = mapscreen_y + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
8018 ComboPosition pos = get_mapscreen_mouse_combo_pos();
8019
8020 if (can_change && isinRect(x, y, startxint, startyint, int32_t(startx + (256 * mapscreen_single_scale) - 1), int32_t(starty + (176 * mapscreen_single_scale) - 1)))
8021 {
8022 Map.StartListCommand();
8023 draw_autocombo_command(pos, 1, cauto_height + change);
8024 Map.FinishListCommand();
8025 }
8026 cauto_height = vbound(cauto_height + change, 1, 9);
8027 }
8028
8029 void draw(bool justcset)
8030 {
8031 combo_pool const& pool = combo_pools[combo_pool_pos];
8032 if(draw_mode == dm_cpool && !pool.valid())
8033 return;
8034 mark_save_dirty();
8035
8036 refresh(rMAP+rSCRMAP);
8037 ComboPosition last_pos = {-1, -1};
8038
8039 Map.StartListCommand();
8040 bool pressframe = true;
8041 while(gui_mouse_b())
8042 {
8043 int32_t x=gui_mouse_x();
8044 int32_t y=gui_mouse_y();
8045 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
8046 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
8047 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
8048 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
8049 int num_combos_width = 16 * Map.getViewSize();
8050 int num_combos_height = 11 * Map.getViewSize();
8051
8052 if(isinRect(x,y,startxint,startyint,int32_t(startx+(256*mapscreen_screenunit_scale)-1),int32_t(starty+(176*mapscreen_screenunit_scale)-1)))
8053 {
8054 int32_t cxstart=(x-startx)/(16*mapscreen_single_scale);
8055 int32_t cystart=(y-starty)/(16*mapscreen_single_scale);
8056 ComboPosition combo_start = {cxstart, cystart};
8057 if (pressframe)
8058 {
8059 last_pos = combo_start;
8060 }
8061 else if (combo_start == last_pos)
8062 {
8063 custom_vsync();
8064 refresh(rALL);
8065 continue;
8066 }
8067 else if(draw_mode == dm_auto)
8068 {
8069 // TODO: support when zoomed out.
8070 if (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE || combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4)
8071 {
8072 // Don't allow moving the brush at anything but cardinal directions while in these modes
8073 bool did_diag = std::abs(combo_start.x - last_pos.x) == 1 && std::abs(combo_start.y - last_pos.y) == 1;
8074
8075 if (did_diag)
8076 {
8077 int32_t oldx = last_pos.x;
8078 int32_t oldy = last_pos.y;
8079 int32_t cx = (oldx * 16 * mapscreen_single_scale) + 8;
8080 int32_t cy = (oldy * 16 * mapscreen_single_scale) + 8;
8081 int32_t nx = x - startxint;
8082 int32_t ny = y - startyint;
8083 if (std::abs(nx - cx) < std::abs(ny - cy))
8084 {
8085 oldy = vbound(oldy + ((ny - cy) < 0 ? -1 : 1), 0, 11);
8086 }
8087 else
8088 {
8089 oldx = vbound(oldx + ((nx - cx) < 0 ? -1 : 1), 0, 15);
8090 }
8091 combo_start = {oldx, oldy};
8092 }
8093 }
8094 }
8095 last_pos = combo_start;
8096
8097 switch(draw_mode)
8098 {
8099 case dm_normal:
8100 {
8101 int32_t cc=Combo;
8102
8103 for(int32_t cy=0; cy+cystart<num_combos_height&&cy<BrushHeight; cy++)
8104 {
8105 for(int32_t cx=0; cx+cxstart<num_combos_width&&cx<BrushWidth; cx++)
8106 {
8107 auto pos = combo_start + ComboPosition{cx, cy};
8108 cc=Combo + cx + cy*4;
8109 Map.DoSetComboCommand(pos, justcset ? -1 : cc, CSet);
8110 }
8111 }
8112
8113 update_combobrush();
8114 }
8115 break;
8116 case dm_cpool:
8117 {
8118 int32_t cid = Combo;
8119 int8_t cs = CSet;
8120 pool.pick(cid,cs);
8121 Map.DoSetComboCommand(combo_start, justcset ? -1 : cid, cs);
8122
8123 update_combobrush();
8124 }
8125 break;
8126
8127 case dm_alias:
8128 {
8129 combo_alias *combo = &combo_aliases[combo_apos];
8130 if(!combo->layermask)
8131 {
8132 int32_t ox=0, oy=0;
8133
8134 switch(alias_origin)
8135 {
8136 case 0:
8137 ox=0;
8138 oy=0;
8139 break;
8140
8141 case 1:
8142 ox=(combo->width);
8143 oy=0;
8144 break;
8145
8146 case 2:
8147 ox=0;
8148 oy=(combo->height);
8149 break;
8150
8151 case 3:
8152 ox=(combo->width);
8153 oy=(combo->height);
8154 break;
8155 }
8156
8157 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8158 {
8159 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8160 {
8161 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8162 {
8163 int32_t p=(cy*(combo->width+1))+cx;
8164
8165 if(combo->combos[p])
8166 {
8167 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8168 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8169 }
8170 }
8171 }
8172 }
8173 }
8174 else
8175 {
8176 int32_t laypos = 0;
8177 int32_t ox=0, oy=0;
8178
8179 switch(alias_origin)
8180 {
8181 case 0:
8182 ox=0;
8183 oy=0;
8184 break;
8185
8186 case 1:
8187 ox=(combo->width);
8188 oy=0;
8189 break;
8190
8191 case 2:
8192 ox=0;
8193 oy=(combo->height);
8194 break;
8195
8196 case 3:
8197 ox=(combo->width);
8198 oy=(combo->height);
8199 break;
8200 }
8201
8202 for(int32_t cz=0; cz<7; cz++)
8203 {
8204 if (cz > 0 && !(combo->layermask & (1<<(cz-1))))
8205 continue;
8206
8207 if (cz > 0)
8208 laypos++;
8209
8210 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8211 {
8212 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8213 {
8214 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8215 {
8216 int32_t p=((cy*(combo->width+1))+cx)+((combo->width+1)*(combo->height+1)*laypos);
8217
8218 if (combo->combos[p])
8219 {
8220 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8221 if(cz > 0 && Map.Scr(pos)->layermap[cz - 1] == 0)
8222 continue;
8223 int prev = CurrentLayer;
8224 CurrentLayer = cz;
8225 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8226 CurrentLayer = prev;
8227 }
8228 }
8229 }
8230 }
8231 }
8232 }
8233
8234 break;
8235 }
8236
8237 case dm_auto:
8238 {
8239 draw_autocombo(combo_start, gui_mouse_b() & 2, pressframe);
8240
8241 combobrushoverride = get_autocombo_floating_cid(combo_start, true);
8242 update_combobrush();
8243 }
8244 }
8245 }
8246 pressframe = false;
8247
8248 custom_vsync();
8249 refresh(rALL);
8250 }
8251
8252 Map.FinishListCommand();
8253 if(AutoBrushRevert)
8254 {
8255 AutoBrushRevert = false;
8256 BrushWidth = 1;
8257 BrushHeight = 1;
8258 }
8259 }
8260
8261 static void replace(ComboPosition start)
8262 {
8263 int32_t cid = Combo;
8264 int8_t cs = CSet;
8265 combo_pool const& pool = combo_pools[combo_pool_pos];
8266 if(draw_mode == dm_cpool && !pool.valid())
8267 return;
8268
8269 int c = start.truncate();
8270 mapscr* scr = Map.Scr(start, CurrentLayer);
8271 if (!scr) return;
8272
8273 int num_combos_width = 16 * Map.getViewSize();
8274 int num_combos_height = 11 * Map.getViewSize();
8275 int targetcombo = scr->data[c];
8276 int targetcset = scr->cset[c];
8277
8278 mark_save_dirty();
8279 Map.StartListCommand();
8280 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
8281 {
8282 for (int x = 0; x < num_combos_width; x++)
8283 {
8284 for (int y = 0; y < num_combos_height; y++)
8285 {
8286 ComboPosition pos = {x, y};
8287 int c = pos.truncate();
8288 mapscr* scr = Map.Scr(pos, CurrentLayer);
8289 if (!scr)
8290 continue;
8291
8292 if ((scr->cset[c]) == targetcset)
8293 {
8294 if(draw_mode == dm_cpool)
8295 pool.pick(cid,cs);
8296 Map.DoSetComboCommand(pos, -1, cs);
8297 }
8298 }
8299 }
8300 }
8301 else
8302 {
8303 for (int x = 0; x < num_combos_width; x++)
8304 {
8305 for (int y = 0; y < num_combos_height; y++)
8306 {
8307 ComboPosition pos = {x, y};
8308 int c = pos.truncate();
8309 mapscr* scr = Map.Scr(pos, CurrentLayer);
8310 if (!scr)
8311 continue;
8312
8313 if(((scr->data[c])==targetcombo) &&
8314 ((scr->cset[c])==targetcset))
8315 {
8316 if(draw_mode == dm_cpool)
8317 pool.pick(cid,cs);
8318 Map.DoSetComboCommand(pos, cid, cs);
8319 }
8320 }
8321 }
8322 }
8323 Map.FinishListCommand();
8324
8325 refresh(rMAP);
8326 }
8327
8328 static void draw_block(ComboPosition start, int32_t w, int32_t h)
8329 {
8330 int32_t cid = Combo;
8331 int8_t cs = CSet;
8332 if(draw_mode == dm_cpool)
8333 {
8334 combo_pool const& pool = combo_pools[combo_pool_pos];
8335 if(!pool.pick(cid,cs)) return;
8336 }
8337
8338 mapscr* scr = Map.Scr(start, CurrentLayer);
8339 if (!scr) return;
8340
8341 mark_save_dirty();
8342 Map.StartListCommand();
8343 for (int32_t y=0; y < h && y < 11*Map.getViewSize(); y++)
8344 for (int32_t x=0; x < w && x < 16*Map.getViewSize(); x++)
8345 {
8346 Map.DoSetComboCommand(start + ComboPosition{x, y}, cid+(y*4)+x, cs);
8347 }
8348
8349 Map.FinishListCommand();
8350 refresh(rMAP+rSCRMAP);
8351 }
8352
8353 static std::vector<ComboPosition> flood_filler(ComboPosition start_pos, bool allow_diagonal, std::function<bool(ComboPosition)> check)
8354 {
8355 std::vector<ComboPosition> seen, queue;
8356
8357 queue.push_back(start_pos);
8358 while (!queue.empty())
8359 {
8360 ComboPosition pos = queue.back();
8361 queue.pop_back();
8362 seen.push_back(pos);
8363
8364 ComboPosition pos2;
8365 #define FLOOD_FILLER_CHECK(dx, dy)\
8366 pos2 = pos + ComboPosition{dx, dy};\
8367 if (std::find(seen.begin(), seen.end(), pos2) == seen.end() && check(pos2))\
8368 queue.push_back(pos2);
8369
8370 FLOOD_FILLER_CHECK(0, 1);
8371 FLOOD_FILLER_CHECK(0, -1);
8372 FLOOD_FILLER_CHECK(1, 0);
8373 FLOOD_FILLER_CHECK(-1, 0);
8374
8375 if (allow_diagonal)
8376 {
8377 FLOOD_FILLER_CHECK(1, 1);
8378 FLOOD_FILLER_CHECK(1, -1);
8379 FLOOD_FILLER_CHECK(-1, 1);
8380 FLOOD_FILLER_CHECK(-1, -1);
8381 }
8382
8383 #undef FLOOD_FILLER_CHECK
8384 }
8385
8386 return seen;
8387 }
8388
8389 static void fill(int32_t targetcombo, int32_t targetcset, ComboPosition start_pos, bool allow_diagonal, bool only_cset)
8390 {
8391 bool rclick = gui_mouse_b() & 2;
8392 bool ignored_combo = false;
8393
8394 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8395 if (!scr)
8396 return;
8397
8398 int num_combos_width = 16 * Map.getViewSize();
8399 int num_combos_height = 11 * Map.getViewSize();
8400
8401 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8402 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8403 return false;
8404
8405 mapscr* scr = Map.Scr(pos, CurrentLayer);
8406 if (!scr || !scr->is_valid())
8407 return false;
8408
8409 int cid = scr->data[pos.truncate()];
8410 int cset = scr->cset[pos.truncate()];
8411
8412 if (draw_mode == dm_auto)
8413 {
8414 combo_auto const& cauto = combo_autos[combo_auto_pos];
8415
8416 ignored_combo = cauto.isIgnoredCombo(cid);
8417 if (rclick)
8418 {
8419 if (cauto.containsCombo(targetcombo))
8420 {
8421 if (!cauto.containsCombo(cid))
8422 return false;
8423 if (cauto.getType() == AUTOCOMBO_REPLACE && ignored_combo)
8424 return false;
8425 }
8426 else
8427 return false;
8428 }
8429 else
8430 {
8431 if (cid != targetcombo && !ignored_combo)
8432 return false;
8433 if (cauto.getType() == AUTOCOMBO_REPLACE && !ignored_combo)
8434 return false;
8435 }
8436
8437 if (cset != targetcset && !ignored_combo)
8438 return false;
8439 }
8440 else
8441 {
8442 if(!only_cset)
8443 {
8444 if (cid != targetcombo)
8445 return false;
8446 }
8447
8448 if (cset != targetcset)
8449 return false;
8450 }
8451
8452 return true;
8453 });
8454
8455 for (auto& pos : combo_positions)
8456 {
8457 int32_t cid = Combo;
8458 int8_t cs = CSet;
8459
8460 if (draw_mode == dm_cpool)
8461 {
8462 combo_pool const& pool = combo_pools[combo_pool_pos];
8463 if (!pool.pick(cid, cs)) continue;
8464 }
8465 else if (draw_mode == dm_auto)
8466 {
8467 combo_auto const& cauto = combo_autos[combo_auto_pos];
8468 if (!cauto.valid())
8469 continue;
8470 if (!rclick && (cauto.containsCombo(targetcombo) && !ignored_combo))
8471 continue;
8472 if (rclick && cauto.getEraseCombo() == targetcombo)
8473 continue;
8474 }
8475
8476 if (draw_mode == dm_auto)
8477 draw_autocombo(pos, rclick);
8478 else
8479 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8480 }
8481 }
8482
8483 static void fill_flag(int32_t targetflag, ComboPosition start_pos, bool allow_diagonal)
8484 {
8485 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8486 if (!scr)
8487 return;
8488
8489 int num_combos_width = 16 * Map.getViewSize();
8490 int num_combos_height = 11 * Map.getViewSize();
8491
8492 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8493 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8494 return false;
8495
8496 mapscr* scr = Map.Scr(pos, CurrentLayer);
8497 if (!scr || !scr->is_valid())
8498 return false;
8499
8500 if (scr->sflag[pos.truncate()] != targetflag)
8501 return false;
8502
8503 return true;
8504 });
8505
8506 for (auto& pos : combo_positions)
8507 Map.DoSetFlagCommand(pos, Flag);
8508 }
8509
8510 static void fill2(int32_t targetcombo, int32_t targetcset, ComboPosition pos, int32_t dir, int32_t diagonal, bool only_cset)
8511 {
8512 mapscr* scr = Map.Scr(pos, CurrentLayer);
8513 if (!scr || !scr->is_valid())
8514 return;
8515
8516 int cid = scr->data[pos.truncate()];
8517 int cset = scr->cset[pos.truncate()];
8518
8519 if (!only_cset)
8520 {
8521 if (cid == targetcombo)
8522 return;
8523 }
8524
8525 if (cset == targetcset)
8526 return;
8527
8528 cid = Combo;
8529 int8_t cs = CSet;
8530 if(draw_mode == dm_cpool)
8531 {
8532 combo_pool const& pool = combo_pools[combo_pool_pos];
8533 if(!pool.pick(cid,cs)) return;
8534 }
8535
8536 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8537
8538 int num_combos_width = 16 * Map.getViewSize();
8539 int num_combos_height = 11 * Map.getViewSize();
8540
8541 if (pos.y > 0 && dir != down)
8542 fill2(targetcombo, targetcset, pos + ComboPosition{0, -1}, up, diagonal, only_cset);
8543 if (pos.y < num_combos_height-1 && dir != up)
8544 fill2(targetcombo, targetcset, pos + ComboPosition{0, 1}, down, diagonal, only_cset);
8545 if (pos.x > 0 && dir != right)
8546 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 0}, left, diagonal, only_cset);
8547 if (pos.x < num_combos_width-1 && dir != left)
8548 fill2(targetcombo, targetcset, pos + ComboPosition{1, 0}, right, diagonal, only_cset);
8549
8550 if (diagonal == 1)
8551 {
8552 if (pos.y > 0 && pos.x > 0 && dir != r_down)
8553 fill2(targetcombo, targetcset, pos + ComboPosition{-1, -1}, l_up, diagonal, only_cset);
8554 if (pos.y < num_combos_height-1 && pos.x < num_combos_width-1 && dir != l_up)
8555 fill2(targetcombo, targetcset, pos + ComboPosition{1, 1}, r_down, diagonal, only_cset);
8556 if (pos.x > 0 && pos.y < num_combos_height-1 && dir != r_up)
8557 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 1}, l_down, diagonal, only_cset);
8558 if (pos.x < num_combos_width-1 && pos.y > 0 && dir != l_down)
8559 fill2(targetcombo, targetcset, pos + ComboPosition{1, -1}, r_up, diagonal, only_cset);
8560 }
8561 }
8562
8563
8564 enum SnapMode
8565 {
8566 SNAP_NONE, SNAP_HALF, SNAP_WHOLE
8567 };
8568 static void snap_xy(int& x, int& y, SnapMode mode, roundType rounding, optional<int> max_x = nullopt, optional<int> max_y = nullopt)
8569 {
8570 if(mode == SNAP_NONE)
8571 {
8572 if(max_x) x = vbound(x,*max_x,0);
8573 if(max_y) y = vbound(y,*max_y,0);
8574 return;
8575 }
8576 int xoff = 0, yoff = 0;
8577 switch(rounding)
8578 {
8579 case ROUND_TO_0:
8580 rounding = ROUND_DOWN;
8581 break;
8582 case ROUND_AWAY_0:
8583 rounding = ROUND_UP;
8584 break;
8585 }
8586 int r = 0;
8587 switch(mode)
8588 {
8589 case SNAP_HALF:
8590 r = 8;
8591 break;
8592 case SNAP_WHOLE:
8593 r = 16;
8594 break;
8595 }
8596 assert(r > 0);
8597 // r must be a power of 2, for bitwise reasons
8598 switch(rounding)
8599 {
8600 case ROUND_DOWN:
8601 break;
8602 case ROUND_UP:
8603 xoff = ((x & (r-1)) ? r : 0);
8604 yoff = ((y & (r-1)) ? r : 0);
8605 break;
8606 case ROUND_NEAREST:
8607 xoff = ((x & (r-1)) >= (r/2) ? r : 0);
8608 yoff = ((y & (r-1)) >= (r/2) ? r : 0);
8609 break;
8610 }
8611 x = (x & ~(r-1)) + xoff;
8612 y = (y & ~(r-1)) + yoff;
8613 if(max_x && x >= *max_x) x = *max_x-r;
8614 else if(max_x && x < 0) x = 0;
8615 if(max_y && y >= *max_y) y = *max_y-r;
8616 else if(max_y && y < 0) y = 0;
8617 }
8618
8619 static void doxypos(byte &px2, byte &py2, int32_t color, SnapMode snap_mode,
8620 SnapMode shift_mode, bool immediately, int32_t cursoroffx,
8621 int32_t cursoroffy, int32_t iconw, int32_t iconh)
8622 {
8623 int32_t tempcb=ComboBrush;
8624 ComboBrush=0;
8625 MouseSprite::set(ZQM_POINT_BOX);
8626
8627 int viz_off_x = (active_visible_screen ? active_visible_screen->dx * 256 : 0);
8628 int viz_off_y = (active_visible_screen ? active_visible_screen->dy * 176 : 0);
8629
8630 int32_t oldpx=px2, oldpy=py2;
8631 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
8632 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
8633 showxypos_x=px2 + viz_off_x;
8634 showxypos_y=py2 + viz_off_y;
8635 showxypos_w=iconw;
8636 showxypos_h=iconh;
8637 showxypos_color=vc(color);
8638 showxypos_icon=!showxypos_dummy;
8639 bool canedit=false;
8640 bool done=false;
8641
8642 clear_tooltip();
8643
8644 while(!done && (!(gui_mouse_b()&2) || immediately))
8645 {
8646 if(!gui_mouse_b() || immediately)
8647 {
8648 canedit=true;
8649 }
8650
8651 // TODO: would be nice if these bounds were based on the individual screen.
8652 if(canedit && gui_mouse_b()==1 && isinRect(gui_mouse_x(),gui_mouse_y(),startxint,startyint,(startxint+(256*mapscreen_screenunit_scale)-1),(startyint+(176*mapscreen_screenunit_scale)-1)))
8653 {
8654 set_mouse_range(startxint,startyint,int32_t(startxint+(256*mapscreen_screenunit_scale)-1),int32_t(startyint+(176*mapscreen_screenunit_scale)-1));
8655
8656 double offx = 0, offy = 0;
8657 roundType rounding = ROUND_DOWN;
8658 if(DragCenterOfSquares)
8659 {
8660 offx -= iconw*mapscreen_single_scale/2;
8661 offy -= iconh*mapscreen_single_scale/2;
8662 rounding = ROUND_NEAREST;
8663 }
8664 int32_t x, y;
8665 do
8666 {
8667 poll_keyboard(); // re-check shift key!
8668 x=int32_t((gui_mouse_x()-startxint+offx)/mapscreen_single_scale)-cursoroffx;
8669 y=int32_t((gui_mouse_y()-startyint+offy)/mapscreen_single_scale)-cursoroffy;
8670 showxypos_cursor_icon=true;
8671 showxypos_cursor_color = showxypos_color;
8672 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8673 showxypos_cursor_x = x-viz_off_x;
8674 showxypos_cursor_y = y-viz_off_y;
8675 snap_xy(showxypos_cursor_x, showxypos_cursor_y, _mode, rounding, 256, 176);
8676 showxypos_cursor_x += viz_off_x;
8677 showxypos_cursor_y += viz_off_y;
8678 custom_vsync();
8679 refresh(rALL | rNOCURSOR);
8680 int32_t xpos[2], ypos[2];
8681 int32_t x1,y1,x2,y2;
8682
8683 char b1[200] = {0};
8684 char b2[200] = {0};
8685 if(showxypos_dummy)
8686 strcpy(b1, "DUMMY MEASURING");
8687 else sprintf(b1, "%d %d",oldpx,oldpy);
8688 sprintf(b2, "%d %d (%d %d)",x-viz_off_x,y-viz_off_y,showxypos_cursor_x-viz_off_x,showxypos_cursor_y-viz_off_y);
8689
8690 int len[2] = {text_length(font,b1),text_length(font,b2)};
8691
8692 if(is_compact)
8693 {
8694 xpos[0] = 4;
8695 ypos[0] = layer_panel.y - 21;
8696 xpos[1] = xpos[0];
8697 ypos[1] = ypos[0]+10;
8698 }
8699 else
8700 {
8701 xpos[0] = 450;
8702 ypos[0] = 405;
8703 xpos[1] = xpos[0];
8704 ypos[1] = ypos[0]+10;
8705 }
8706
8707 x1 = xpos[0];
8708 y1 = ypos[0];
8709 x2 = xpos[0];
8710 y2 = ypos[0];
8711 for(auto q = 0; q < 2; ++q)
8712 {
8713 if(xpos[q] < x1)
8714 x1 = xpos[q];
8715 if(ypos[q] < y1)
8716 y1 = ypos[q];
8717 if(ypos[q] > y2)
8718 y2 = ypos[q];
8719 if(xpos[q] + len[q] > x2)
8720 x2 = xpos[q] + len[q];
8721 }
8722 x1 -= 4;
8723 y1 -= 2;
8724 y2 += text_height(font)+2;
8725
8726 auto minx = zc_min(xpos[0],xpos[1]);
8727 auto miny = zc_min(ypos[0],ypos[1]);
8728 rectfill(screen,x1,y1,x2,y2,vc(0));
8729 textprintf_ex(screen,font,xpos[0],ypos[0],vc(15),vc(0),"%s",b1);
8730 textprintf_ex(screen,font,xpos[1],ypos[1],vc(15),vc(0),"%s",b2);
8731 update_hw_screen();
8732 }
8733 while(gui_mouse_b()==1);
8734
8735 if(gui_mouse_b()==0)
8736 {
8737 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8738 int x2 = vbound(x-viz_off_x,0,255);
8739 int y2 = vbound(y-viz_off_y,0,175);
8740 snap_xy(x2, y2, _mode, rounding, 256, 176);
8741 px2=byte(x2);
8742 py2=byte(y2);
8743 }
8744
8745 set_mouse_range(0,0,zq_screen_w-1,zq_screen_h-1);
8746 done=true;
8747 }
8748
8749 if(keypressed())
8750 {
8751 switch(readkey()>>8)
8752 {
8753 case KEY_ESC:
8754 case KEY_ENTER:
8755 goto finished;
8756 }
8757 }
8758
8759 custom_vsync();
8760 refresh(rALL | rNOCURSOR);
8761 }
8762
8763 finished:
8764 MouseSprite::set(ZQM_NORMAL);
8765 refresh(rMAP+rMENU);
8766
8767 while(gui_mouse_b())
8768 {
8769 /* do nothing */
8770 rest(1);
8771 }
8772
8773 showxypos_x=-1000;
8774 showxypos_y=-1000;
8775 showxypos_color=-1000;
8776 showxypos_ffc=-1000;
8777 showxypos_icon=false;
8778 showxypos_cursor_x=-1000;
8779 showxypos_cursor_y=-1000;
8780 showxypos_cursor_icon=false;
8781 showxypos_cursor_color=-1000;
8782 showxypos_dummy=false;
8783
8784 if(px2!=oldpx||py2!=oldpy)
8785 {
8786 mark_save_dirty();
8787 }
8788
8789 ComboBrush=tempcb;
8790 }
8791 static void doxypos(byte &px2,byte &py2,int32_t color,SnapMode snap_mode, optional<SnapMode> shift_mode = nullopt)
8792 {
8793 doxypos(px2,py2,color,snap_mode,shift_mode ? *shift_mode : snap_mode,false,0,0,16,16);
8794 }
8795
8796 bool placing_flags = false;
8797 void doflags()
8798 {
8799 placing_flags = true;
8800 int of=Flags;
8801 Flags=cFLAGS;
8802 refresh(rMAP | rNOCURSOR);
8803
8804 bool canedit=false;
8805 bool didShift = false;
8806 int tFlag = Flag;
8807 while(!(gui_mouse_b()&2) && !handle_close_btn_quit())
8808 {
8809 int x=gui_mouse_x();
8810 int y=gui_mouse_y();
8811 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
8812 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
8813 int startxint=mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
8814 int startyint=mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
8815 int cx=(x-startxint)/int(16*mapscreen_single_scale);
8816 int cy=(y-startyint)/int(16*mapscreen_single_scale);
8817 ComboPosition combo_pos = {cx, cy};
8818 int c = combo_pos.truncate();
8819
8820 if(!gui_mouse_b())
8821 canedit=true;
8822 bool shift = key[KEY_LSHIFT] || key[KEY_RSHIFT];
8823
8824 if(canedit && gui_mouse_b()==1 && isinRect(x,y,startxint,startyint,int(startx+(256*mapscreen_screenunit_scale)-1),int(starty+(176*mapscreen_screenunit_scale)-1)))
8825 {
8826 mapscr* cur_scr = Map.Scr(combo_pos, CurrentLayer);
8827 if (!cur_scr) continue;
8828
8829 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
8830
8831 if(key[KEY_ALT]||key[KEY_ALTGR])
8832 Flag = cur_scr->sflag[c];
8833 else
8834 {
8835 mark_save_dirty();
8836 int tflag = Flag;
8837 if(shift)
8838 Flag = mfNONE;
8839 if(CurrentLayer!=0)
8840 {
8841 // Notify if they are using a flag that doesn't work on this layer.
8842 if(!skipLayerWarning && ((Flag >= mfTRAP_H && Flag < mfPUSHD) || (Flag == mfFAIRY) || (Flag == mfMAGICFAIRY)
8843 || (Flag == mfALLFAIRY) || (Flag == mfRAFT) || (Flag == mfRAFT_BRANCH)
8844 || (Flag == mfDIVE_ITEM) || (Flag == mfARMOS_SECRET) || (Flag == mfNOENEMY)
8845 || (Flag == mfZELDA)))
8846 {
8847 InfoDialog("Notice","You are currently working on layer "
8848 +to_string(CurrentLayer)
8849 +". This combo flag does not function on layers above '0'.").show();
8850 }
8851 if(!skipLayerWarning && CurrentLayer > 2 &&
8852 ((Flag == mfBLOCKHOLE) || (Flag >= mfPUSHD && Flag < mfNOBLOCKS)
8853 || (Flag == mfPUSHUD) || (Flag == mfPUSH4)))
8854 {
8855 InfoDialog("Notice","You are currently working on layer "
8856 +to_string(CurrentLayer)
8857 +". This combo flag does not function on layers above '2'.").show();
8858 }
8859 }
8860 if(CHECK_CTRL_CMD)
8861 {
8862 switch(fill_type)
8863 {
8864 case 0:
8865 flood_flag();
8866 break;
8867
8868 case 1:
8869 case 3:
8870 fill_4_flag();
8871 break;
8872
8873 case 2:
8874 case 4:
8875 fill_8_flag();
8876 break;
8877 }
8878 }
8879 else
8880 {
8881 Map.DoSetFlagCommand(combo_pos, Flag);
8882 }
8883 Flag = tflag;
8884 }
8885 }
8886
8887 if(mouse_z)
8888 {
8889 for(int i=0; i<abs(mouse_z); ++i)
8890 {
8891 if(mouse_z>0)
8892 onIncreaseFlag();
8893 else
8894 onDecreaseFlag();
8895 }
8896
8897 position_mouse_z(0);
8898 }
8899
8900 if(keypressed())
8901 {
8902 int k = readkey();
8903 switch(k>>8)
8904 {
8905 case KEY_ESC:
8906 case KEY_ENTER:
8907 goto finished;
8908 }
8909 object_message(dialogs+1, MSG_XCHAR, k);
8910 Flags=cFLAGS;
8911 }
8912
8913 MouseSprite::set(ZQM_FLAG_0+(shift?0:Flag%16));
8914
8915 refresh(rALL | rCLEAR | rNOCURSOR);
8916 custom_vsync();
8917 }
8918
8919 finished:
8920 Flags=of;
8921 placing_flags = false;
8922 MouseSprite::set(ZQM_NORMAL);
8923 refresh(rMAP+rMENU);
8924
8925 while(gui_mouse_b())
8926 {
8927 /* do nothing */
8928 rest(1);
8929 }
8930 }
8931
8932 // Drag FFCs around
8933 static void moveffc(int i, int cx, int cy)
8934 {
8935 mapscr* scr = active_visible_screen->scr;
8936 int screen = active_visible_screen->screen;
8937
8938 int32_t ffx = vbound(scr->ffcs[i].x.getFloor(),0,240);
8939 int32_t ffy = vbound(scr->ffcs[i].y.getFloor(),0,160);
8940 int32_t offx = ffx, offy = ffy;
8941 showxypos_ffc = i;
8942 doxypos((byte&)ffx,(byte&)ffy,15,SNAP_HALF,SNAP_NONE,true,0,0,(scr->ffTileWidth(i)*16),(scr->ffTileHeight(i)*16));
8943 if(ffx > 240) ffx = 240;
8944 if(ffy > 160) ffy = 160;
8945 if((ffx != offx) || (ffy != offy))
8946 {
8947 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
8948 set_ffc_data.x = ffx;
8949 set_ffc_data.y = ffy;
8950 Map.DoSetFFCCommand(Map.getCurrMap(), screen, i, set_ffc_data);
8951 mark_save_dirty();
8952 }
8953 }
8954
8955 void set_brush_width(int32_t width);
8956 void set_brush_height(int32_t height);
8957
8958 int32_t set_brush_width_1()
8959 {
8960 set_brush_width(1);
8961 return D_O_K;
8962 }
8963 int32_t set_brush_width_2()
8964 {
8965 set_brush_width(2);
8966 return D_O_K;
8967 }
8968 int32_t set_brush_width_3()
8969 {
8970 set_brush_width(3);
8971 return D_O_K;
8972 }
8973 int32_t set_brush_width_4()
8974 {
8975 set_brush_width(4);
8976 return D_O_K;
8977 }
8978 int32_t set_brush_width_5()
8979 {
8980 set_brush_width(5);
8981 return D_O_K;
8982 }
8983 int32_t set_brush_width_6()
8984 {
8985 set_brush_width(6);
8986 return D_O_K;
8987 }
8988 int32_t set_brush_width_7()
8989 {
8990 set_brush_width(7);
8991 return D_O_K;
8992 }
8993 int32_t set_brush_width_8()
8994 {
8995 set_brush_width(8);
8996 return D_O_K;
8997 }
8998 int32_t set_brush_width_9()
8999 {
9000 set_brush_width(9);
9001 return D_O_K;
9002 }
9003 int32_t set_brush_width_10()
9004 {
9005 set_brush_width(10);
9006 return D_O_K;
9007 }
9008 int32_t set_brush_width_11()
9009 {
9010 set_brush_width(11);
9011 return D_O_K;
9012 }
9013 int32_t set_brush_width_12()
9014 {
9015 set_brush_width(12);
9016 return D_O_K;
9017 }
9018 int32_t set_brush_width_13()
9019 {
9020 set_brush_width(13);
9021 return D_O_K;
9022 }
9023 int32_t set_brush_width_14()
9024 {
9025 set_brush_width(14);
9026 return D_O_K;
9027 }
9028 int32_t set_brush_width_15()
9029 {
9030 set_brush_width(15);
9031 return D_O_K;
9032 }
9033 int32_t set_brush_width_16()
9034 {
9035 set_brush_width(16);
9036 return D_O_K;
9037 }
9038
9039 int32_t set_brush_height_1()
9040 {
9041 set_brush_height(1);
9042 return D_O_K;
9043 }
9044 int32_t set_brush_height_2()
9045 {
9046 set_brush_height(2);
9047 return D_O_K;
9048 }
9049 int32_t set_brush_height_3()
9050 {
9051 set_brush_height(3);
9052 return D_O_K;
9053 }
9054 int32_t set_brush_height_4()
9055 {
9056 set_brush_height(4);
9057 return D_O_K;
9058 }
9059 int32_t set_brush_height_5()
9060 {
9061 set_brush_height(5);
9062 return D_O_K;
9063 }
9064 int32_t set_brush_height_6()
9065 {
9066 set_brush_height(6);
9067 return D_O_K;
9068 }
9069 int32_t set_brush_height_7()
9070 {
9071 set_brush_height(7);
9072 return D_O_K;
9073 }
9074 int32_t set_brush_height_8()
9075 {
9076 set_brush_height(8);
9077 return D_O_K;
9078 }
9079 int32_t set_brush_height_9()
9080 {
9081 set_brush_height(9);
9082 return D_O_K;
9083 }
9084 int32_t set_brush_height_10()
9085 {
9086 set_brush_height(10);
9087 return D_O_K;
9088 }
9089 int32_t set_brush_height_11()
9090 {
9091 set_brush_height(11);
9092 return D_O_K;
9093 }
9094
9095
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_width_menu
9096 204 {
9097
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1", set_brush_width_1 },
9098
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2", set_brush_width_2 },
9099
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3", set_brush_width_3 },
9100
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4", set_brush_width_4 },
9101
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "5", set_brush_width_5 },
9102
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "6", set_brush_width_6 },
9103
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "7", set_brush_width_7 },
9104
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "8", set_brush_width_8 },
9105
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "9", set_brush_width_9 },
9106
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "10", set_brush_width_10 },
9107
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "11", set_brush_width_11 },
9108
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "12", set_brush_width_12 },
9109
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "13", set_brush_width_13 },
9110
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "14", set_brush_width_14 },
9111
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "15", set_brush_width_15 },
9112
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "16", set_brush_width_16 },
9113 };
9114
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_height_menu
9115 144 {
9116
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1", set_brush_height_1 },
9117
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2", set_brush_height_2 },
9118
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3", set_brush_height_3 },
9119
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4", set_brush_height_4 },
9120
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "5", set_brush_height_5 },
9121
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "6", set_brush_height_6 },
9122
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "7", set_brush_height_7 },
9123
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "8", set_brush_height_8 },
9124
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "9", set_brush_height_9 },
9125
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "10", set_brush_height_10 },
9126
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "11", set_brush_height_11 },
9127 };
9128
9129 int toggle_autobrush();
9130 int toggle_combobrush();
9131 int toggle_floatbrush();
9132 enum
9133 {
9134 MENUID_BRUSH_AUTOBRUSH,
9135 MENUID_BRUSH_WIDTH,
9136 MENUID_BRUSH_HEIGHT,
9137 MENUID_BRUSH_COMBOBRUSH,
9138 MENUID_BRUSH_FLOATBRUSH,
9139 };
9140
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_menu
9141 72 {
9142
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "AutoBrush", toggle_autobrush, MENUID_BRUSH_AUTOBRUSH },
9143
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Brush Width ", &brush_width_menu, MENUID_BRUSH_WIDTH },
9144
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Brush Height ", &brush_height_menu, MENUID_BRUSH_HEIGHT },
9145
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "ComboBrush", toggle_combobrush, MENUID_BRUSH_COMBOBRUSH },
9146
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "FloatBrush", toggle_floatbrush, MENUID_BRUSH_FLOATBRUSH },
9147 };
9148 int toggle_autobrush()
9149 {
9150 AutoBrush = AutoBrush ? 0 : 1;
9151 BrushWidth = BrushHeight = 1;
9152 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9153 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9154 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9155 zc_set_config("zquest","autobrush",AutoBrush);
9156 return D_O_K;
9157 }
9158 int toggle_combobrush()
9159 {
9160 ComboBrush = ComboBrush ? 0 : 1;
9161 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9162 zc_set_config("zquest","combo_brush",ComboBrush);
9163 return D_O_K;
9164 }
9165 int toggle_floatbrush()
9166 {
9167 FloatBrush = FloatBrush ? 0 : 1;
9168 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9169 zc_set_config("zquest","float_brush",FloatBrush);
9170 return D_O_K;
9171 }
9172
9173 int32_t set_flood();
9174 int32_t set_fill_4();
9175 int32_t set_fill_8();
9176 int32_t set_fill2_4();
9177 int32_t set_fill2_8();
9178
9179 // Sets every combo.
9180 void flood()
9181 {
9182 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9183 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9184 if (!scr || !scr->is_valid())
9185 return;
9186
9187 mark_save_dirty();
9188
9189 bool include_combos = !(key[KEY_LSHIFT]||key[KEY_RSHIFT]);
9190
9191 int num_combos_width = 16 * Map.getViewSize();
9192 int num_combos_height = 11 * Map.getViewSize();
9193
9194 Map.StartListCommand();
9195 for (int x = 0; x < num_combos_width; x++)
9196 {
9197 for (int y = 0; y < num_combos_height; y++)
9198 {
9199 ComboPosition pos = {x, y};
9200 mapscr* scr = Map.Scr(pos, CurrentLayer);
9201 if (!scr || !scr->is_valid())
9202 continue;
9203
9204 if (draw_mode == dm_auto)
9205 draw_autocombo(pos, gui_mouse_b() & 2);
9206 else
9207 Map.DoSetComboCommand(pos, include_combos ? Combo : -1, CSet);
9208 }
9209 }
9210 Map.FinishListCommand();
9211
9212 refresh(rMAP+rSCRMAP);
9213 }
9214 void flood_flag()
9215 {
9216 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9217 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9218 if (!scr || !scr->is_valid())
9219 return;
9220
9221 mark_save_dirty();
9222
9223 int num_combos_width = 16 * Map.getViewSize();
9224 int num_combos_height = 11 * Map.getViewSize();
9225
9226 Map.StartListCommand();
9227 for (int x = 0; x < num_combos_width; x++)
9228 {
9229 for (int y = 0; y < num_combos_height; y++)
9230 {
9231 ComboPosition pos = {x, y};
9232 mapscr* scr = Map.Scr(pos, CurrentLayer);
9233 if (!scr || !scr->is_valid())
9234 continue;
9235
9236 Map.DoSetFlagCommand(pos, Flag);
9237 }
9238 }
9239 Map.FinishListCommand();
9240
9241 refresh(rMAP+rSCRMAP);
9242 }
9243
9244 void fill_4()
9245 {
9246 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9247 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9248 if (!scr)
9249 return;
9250
9251 int c = pos.truncate();
9252 if (draw_mode == dm_cpool || draw_mode == dm_auto
9253 || (scr->cset[c]!=CSet || (scr->data[c]!=Combo && !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9254 {
9255 mark_save_dirty();
9256
9257 Map.StartListCommand();
9258 if (draw_mode == dm_auto && (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE ||
9259 combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4))
9260 {
9261 draw_autocombo_command(pos);
9262 }
9263 else
9264 {
9265 bool allow_diagonal = false;
9266 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT] || key[KEY_RSHIFT]));
9267 }
9268 Map.FinishListCommand();
9269 refresh(rMAP+rSCRMAP);
9270 }
9271 }
9272 void fill_4_flag()
9273 {
9274 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9275 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9276 if (!scr)
9277 return;
9278
9279 int flag = scr->sflag[pos.truncate()];
9280 if (flag != Flag)
9281 {
9282 mark_save_dirty();
9283
9284 Map.StartListCommand();
9285 bool allow_diagonal = false;
9286 fill_flag(flag, pos, allow_diagonal);
9287 Map.FinishListCommand();
9288 refresh(rMAP+rSCRMAP);
9289 }
9290 }
9291 void fill_8()
9292 {
9293 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9294 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9295 if (!scr)
9296 return;
9297
9298 int c = pos.truncate();
9299 if (draw_mode == dm_cpool || draw_mode == dm_auto
9300 || (scr->cset[c] != CSet ||
9301 (scr->data[c] != Combo &&
9302 !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9303 {
9304 mark_save_dirty();
9305
9306 Map.StartListCommand();
9307 bool allow_diagonal = true;
9308 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9309 Map.FinishListCommand();
9310
9311 refresh(rMAP+rSCRMAP);
9312 }
9313 }
9314 void fill_8_flag()
9315 {
9316 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9317 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9318 if (!scr)
9319 return;
9320
9321 int flag = scr->sflag[pos.truncate()];
9322 if (flag != Flag)
9323 {
9324 mark_save_dirty();
9325
9326 Map.StartListCommand();
9327 bool allow_diagonal = true;
9328 fill_flag(flag, pos, allow_diagonal);
9329 Map.FinishListCommand();
9330 refresh(rMAP+rSCRMAP);
9331 }
9332 }
9333
9334 void fill2_4()
9335 {
9336 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9337 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9338 if (!scr)
9339 return;
9340
9341 mark_save_dirty();
9342
9343 Map.StartListCommand();
9344 fill2(Combo, CSet, pos, 255, 0, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9345 Map.FinishListCommand();
9346 refresh(rMAP+rSCRMAP);
9347 }
9348
9349 void fill2_8()
9350 {
9351 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9352 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9353 if (!scr)
9354 return;
9355
9356 mark_save_dirty();
9357
9358 Map.StartListCommand();
9359 fill2(Combo, CSet, pos, 255, 1, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9360 Map.FinishListCommand();
9361
9362 refresh(rMAP+rSCRMAP);
9363 }
9364
9365
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu fill_menu
9366 72 {
9367
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Flood", set_flood, 0 },
9368
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill (4-way)", set_fill_4, 1 },
9369
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill (8-way)", set_fill_8, 2 },
9370
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill2 (4-way)", set_fill2_4, 3 },
9371
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill2 (8-way)", set_fill2_8, 4 },
9372 };
9373 void set_filltype(int ty)
9374 {
9375 fill_type = ty;
9376 fill_menu.select_only_uid(ty);
9377 }
9378
9379 int32_t set_flood()
9380 {
9381 set_filltype(0);
9382 return D_O_K;
9383 }
9384
9385 int32_t set_fill_4()
9386 {
9387 set_filltype(1);
9388 return D_O_K;
9389 }
9390
9391 int32_t set_fill_8()
9392 {
9393 set_filltype(2);
9394 return D_O_K;
9395 }
9396
9397 int32_t set_fill2_4()
9398 {
9399 set_filltype(3);
9400 return D_O_K;
9401 }
9402
9403 int32_t set_fill2_8()
9404 {
9405 set_filltype(4);
9406 return D_O_K;
9407 }
9408
9409 int32_t draw_block_1_2()
9410 {
9411 draw_block(mouse_combo_pos,1,2);
9412 return D_O_K;
9413 }
9414
9415 int32_t draw_block_2_1()
9416 {
9417 draw_block(mouse_combo_pos,2,1);
9418 return D_O_K;
9419 }
9420
9421 int32_t draw_block_2_2()
9422 {
9423 draw_block(mouse_combo_pos,2,2);
9424 return D_O_K;
9425 }
9426
9427 int32_t draw_block_2_3()
9428 {
9429 draw_block(mouse_combo_pos,2,3);
9430 return D_O_K;
9431 }
9432
9433 int32_t draw_block_3_2()
9434 {
9435 draw_block(mouse_combo_pos,3,2);
9436 return D_O_K;
9437 }
9438
9439 int32_t draw_block_3_3()
9440 {
9441 draw_block(mouse_combo_pos,3,3);
9442 return D_O_K;
9443 }
9444
9445 int32_t draw_block_4_2()
9446 {
9447 draw_block(mouse_combo_pos,4,2);
9448 return D_O_K;
9449 }
9450
9451 int32_t draw_block_4_4()
9452 {
9453 draw_block(mouse_combo_pos,4,4);
9454 return D_O_K;
9455 }
9456
9457
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu draw_block_menu
9458 108 {
9459
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1x2", draw_block_1_2 },
9460
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x1", draw_block_2_1 },
9461
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x2", draw_block_2_2 },
9462
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x3", draw_block_2_3 },
9463
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3x2", draw_block_3_2 },
9464
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3x3", draw_block_3_3 },
9465
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4x2", draw_block_4_2 },
9466
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4x4", draw_block_4_4 },
9467 };
9468
9469
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_screen_menu
9470 60 {
9471
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste", onPaste },
9472
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste All", onPasteAll },
9473
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste to All", onPasteToAll },
9474
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste All to All", onPasteAllToAll },
9475 };
9476
9477 int32_t scrollto_cmb(int32_t cid)
9478 {
9479 auto& sqr = combolist[current_combolist];
9480 int32_t res = vbound(cid-(sqr.w*sqr.h/2),0,MAXCOMBOS-(sqr.w*sqr.h));
9481 res -= res%sqr.w;
9482 return res;
9483 }
9484 int32_t scrollto_alias(int32_t alid)
9485 {
9486 auto& sqr = comboaliaslist[current_comboalist];
9487 int32_t res = vbound(alid-(sqr.w*sqr.h/2),0,MAXCOMBOALIASES-(sqr.w*sqr.h));
9488 res -= res%sqr.w;
9489 return res;
9490 }
9491
9492 int32_t scrollto_cpool(int32_t cpid)
9493 {
9494 auto& sqr = comboaliaslist[current_cpoollist];
9495 int32_t res = vbound(cpid-(sqr.w*sqr.h/2),0,MAXCOMBOPOOLS-(sqr.w*sqr.h));
9496 res -= res%sqr.w;
9497 return res;
9498 }
9499
9500 int32_t scrollto_cauto(int32_t caid)
9501 {
9502 auto& sqr = comboaliaslist[current_cautolist];
9503 int32_t res = vbound(caid - (sqr.w * sqr.h / 2), 0, MAXCOMBOPOOLS - (sqr.w * sqr.h));
9504 res -= res % sqr.w;
9505 return res;
9506 }
9507
9508 void add_favorite_combo_block(int32_t favind, int32_t cid, bool force)
9509 {
9510 int32_t w = vbound(BrushWidth, 1, 4);
9511 int32_t h = vbound(BrushHeight, 1, 7);
9512 for (int32_t xi = 0; xi < w; ++xi)
9513 {
9514 for (int32_t yi = 0; yi < h; ++yi)
9515 {
9516 int32_t cx = cid % 4;
9517 int32_t cy = cid / 4;
9518 int32_t cc = (cy + yi) * 4 + cx + xi;
9519 int32_t fx = favind % FAVORITECOMBO_PER_ROW;
9520 int32_t fy = favind / FAVORITECOMBO_PER_ROW;
9521 int32_t fc = (fy + yi) * FAVORITECOMBO_PER_ROW + fx + xi + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
9522
9523 if (cx + xi < 4 && cc < MAXCOMBOS && fx + xi < FAVORITECOMBO_PER_ROW && fy + yi < FAVORITECOMBO_PER_COLUMN)
9524 {
9525 if (favorite_combos[fc] < 0 || force)
9526 {
9527 favorite_combo_modes[fc] = dm_normal;
9528 favorite_combos[fc] = cc;
9529 }
9530 }
9531 }
9532 }
9533 }
9534
9535 void onRCSelectCombo(int32_t c)
9536 {
9537 int32_t drawmap, drawscr;
9538
9539 if(CurrentLayer==0)
9540 {
9541 drawmap=Map.getCurrMap();
9542 drawscr=Map.getCurrScr();
9543 }
9544 else
9545 {
9546 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9547 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9548 }
9549 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9550 if(!draw_mapscr) return;
9551
9552 Combo=draw_mapscr->data[c];
9553 if(AutoBrush)
9554 BrushWidth = BrushHeight = 1;
9555 }
9556
9557 void onRCScrollToombo(int32_t c)
9558 {
9559 int32_t drawmap, drawscr;
9560
9561 if(CurrentLayer==0)
9562 {
9563 drawmap=Map.getCurrMap();
9564 drawscr=Map.getCurrScr();
9565 }
9566 else
9567 {
9568 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9569 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9570 }
9571 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9572 if(!draw_mapscr) return;
9573
9574 auto& sqr = combolist[current_combolist];
9575 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
9576 }
9577
9578 enum
9579 {
9580 MENUID_RCSCREEN_PASTE,
9581 MENUID_RCSCREEN_ADVPASTE,
9582 MENUID_RCSCREEN_SPECPASTE,
9583 };
9584
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu rc_menu_screen
9585 60 {
9586
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Copy Screen", onCopy },
9587
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste Screen", &paste_screen_menu, MENUID_RCSCREEN_PASTE },
9588
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "...Advanced Paste", &paste_menu, MENUID_RCSCREEN_ADVPASTE },
9589
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "...Special Paste", &paste_item_menu, MENUID_RCSCREEN_SPECPASTE },
9590 };
9591
9592 void call_options_dlg();
9593 int32_t onOptions()
9594 {
9595 call_options_dlg();
9596 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9597 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9598 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9599 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9600 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9601 return D_O_K;
9602 }
9603
9604 void follow_twarp(int warpindex)
9605 {
9606 if(warpindex >= 4)
9607 {
9608 InfoDialog("Random Tile Warp",
9609 "This is a random tile warp combo, so it chooses"
9610 " randomly between the screen's four Tile Warps.").show();
9611 warpindex=zc_oldrand()&3;
9612 }
9613
9614 int32_t tm = Map.getCurrMap();
9615 int32_t ts = Map.getCurrScr();
9616 int32_t wt = Map.CurrScr()->tilewarptype[warpindex];
9617
9618 if(wt==wtCAVE || wt==wtNOWARP)
9619 {
9620 char buf[56];
9621 InfoDialog(warptype_string[wt],fmt::format("This screen's Tile Warp {} is set to {}, so it doesn't lead to another screen.",'A'+warpindex,warptype_string[wt]));
9622 return;
9623 }
9624
9625 Map.dowarp(0,warpindex);
9626
9627 if(ts!=Map.getCurrScr() || tm!=Map.getCurrMap())
9628 {
9629 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(warpindex*2))&3;
9630 FlashWarpClk = 32;
9631 }
9632 }
9633 void edit_twarp(int warpindex)
9634 {
9635 if(warpindex>=4)
9636 {
9637 InfoDialog("Random Tile Warp",
9638 "This is a random tile warp combo, so it chooses"
9639 " randomly between the screen's four Tile Warps.").show();
9640 warpindex=zc_oldrand()&3;
9641 }
9642
9643 if(warpindex > -1 && warpindex < 4)
9644 onTileWarpIndex(warpindex);
9645 }
9646
9647 int toggle_linked_scrolling()
9648 {
9649 LinkedScroll = LinkedScroll ? 0 : 1;
9650 zc_set_config("zquest","linked_comboscroll",LinkedScroll);
9651 return D_O_K;
9652 }
9653 void on_scroll_cpane()
9654 {
9655 switch (draw_mode)
9656 {
9657 case dm_alias:
9658 combo_alistpos[current_comboalist] = scrollto_alias(combo_apos);
9659 break;
9660 case dm_cpool:
9661 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
9662 break;
9663 case dm_auto:
9664 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
9665 break;
9666 default:
9667 First[current_combolist] = scrollto_cmb(Combo);
9668 break;
9669 }
9670 }
9671 void on_edit_cpane()
9672 {
9673 switch (draw_mode)
9674 {
9675 case dm_alias:
9676 onEditComboAlias();
9677 break;
9678 case dm_cpool:
9679 onEditComboPool();
9680 break;
9681 case dm_auto:
9682 onEditAutoCombo();
9683 break;
9684 default:
9685 reset_combo_animations();
9686 reset_combo_animations2();
9687 edit_combo(Combo, true, CSet);
9688 setup_combo_animations();
9689 setup_combo_animations2();
9690 break;
9691 }
9692 }
9693 void open_combo_pages(optional<int> cid)
9694 {
9695 int cmb_id = cid ? *cid : 0;
9696 combo_screen(cmb_id >> 8, cmb_id);
9697 }
9698 void on_cpane_page()
9699 {
9700 switch(draw_mode)
9701 {
9702 case dm_normal:
9703 open_combo_pages(Combo);
9704 break;
9705 case dm_alias:
9706 call_alias_pages(combo_apos);
9707 break;
9708 case dm_auto:
9709 call_autoc_pages(combo_auto_pos);
9710 break;
9711 case dm_cpool:
9712 call_cpool_pages(combo_pool_pos);
9713 break;
9714 }
9715 }
9716 void open_cpane_tilepage()
9717 {
9718 onGotoTiles(combobuf[Combo].o_tile);
9719 }
9720 static int _clicked_fav = 0;
9721 void fav_rc_remove()
9722 {
9723 favorite_combo_modes[_clicked_fav] = dm_normal;
9724 favorite_combos[_clicked_fav] = -1;
9725 mark_save_dirty();
9726 }
9727 void popup_favorites_rc(int f, int x, int y)
9728 {
9729 _clicked_fav = f;
9730 string type;
9731 switch (draw_mode)
9732 {
9733 case dm_alias:
9734 type = "Alias";
9735 break;
9736 case dm_cpool:
9737 type = "Pool";
9738 break;
9739 case dm_auto:
9740 type = "Autocombo";
9741 break;
9742 case dm_normal:
9743 type = "Combo";
9744 break;
9745 default: return;
9746 }
9747 NewMenu rcmenu
9748 {
9749 { fmt::format("Scroll to {}", type), on_scroll_cpane },
9750 { fmt::format("Edit {}", type), on_edit_cpane },
9751 { fmt::format("Open {} Page", type), on_cpane_page },
9752 { fmt::format("Remove Fav {}", type), fav_rc_remove },
9753 };
9754 switch (draw_mode)
9755 {
9756 case dm_normal:
9757 rcmenu.add({
9758 {},
9759 { "Open Tile Page", open_cpane_tilepage },
9760 });
9761 break;
9762 }
9763 rcmenu.pop(x, y);
9764 }
9765 void popup_cpane_rc(int x, int y)
9766 {
9767 string type;
9768 switch (draw_mode)
9769 {
9770 case dm_alias:
9771 type = "Alias";
9772 break;
9773 case dm_cpool:
9774 type = "Pool";
9775 break;
9776 case dm_auto:
9777 type = "Autocombo";
9778 break;
9779 case dm_normal:
9780 type = "Combo";
9781 break;
9782 default: return;
9783 }
9784 NewMenu rcmenu;
9785 switch(draw_mode)
9786 {
9787 case dm_normal:
9788 rcmenu.add({
9789 { fmt::format("Edit {}", type), on_edit_cpane },
9790 { fmt::format("Open {} Page", type), on_cpane_page },
9791 { "Open Tile Page", open_cpane_tilepage },
9792 { "Combo Locations", onComboLocationReport },
9793 {},
9794 { "Scroll to Page...", onGotoPage },
9795 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9796 });
9797 break;
9798 case dm_alias:
9799 case dm_cpool:
9800 case dm_auto:
9801 rcmenu.add({
9802 { fmt::format("Edit {}", type), on_edit_cpane },
9803 { fmt::format("Open {} Page", type), on_cpane_page },
9804 {},
9805 { "Scroll to Page...", onGotoPage },
9806 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9807 });
9808 break;
9809 }
9810 rcmenu.pop(x, y);
9811 }
9812
9813 void set_brush_width(int32_t width)
9814 {
9815 BrushWidth = width;
9816 for(int q = 0; q < brush_width_menu.size(); ++q)
9817 brush_width_menu.at(q)->select(q==BrushWidth-1);
9818 refresh(rALL);
9819 }
9820
9821 void set_brush_height(int32_t height)
9822 {
9823 BrushHeight = height;
9824 for(int q = 0; q < brush_height_menu.size(); ++q)
9825 brush_height_menu.at(q)->select(q==BrushHeight-1);
9826 refresh(rALL);
9827 }
9828
9829 1 void restore_mouse()
9830 {
9831 1 ComboBrushPause=1;
9832 1 MouseSprite::set(ZQM_NORMAL);
9833 1 }
9834
9835 static int32_t comboa_cnt=0;
9836 static int32_t combop_cnt=0;
9837 static int32_t layer_cnt=0;
9838
9839 static char paste_ffc_menu_text[21];
9840 static char paste_ffc_menu_text2[21];
9841 static char follow_warp_menu_text[21];
9842 static char follow_warp_menu_text2[21];
9843
9844 static int fake_mouse_b(){return 0;}
9845 static int (*mouseb_proc)();
9846 static bool killed_mouse = false;
9847 void zq_killmouse()
9848 {
9849 if(killed_mouse) return;
9850 mouseb_proc = gui_mouse_b;
9851 gui_mouse_b = fake_mouse_b;
9852 killed_mouse = true;
9853 }
9854 void zq_restoremouse()
9855 {
9856 if(!killed_mouse) return;
9857 gui_mouse_b = mouseb_proc;
9858 killed_mouse = false;
9859 }
9860
9861
9862 void domouse()
9863 {
9864 static int mouse_down = 0;
9865 static int32_t scrolldelay = 0;
9866 auto mousexy = zc_get_mouse();
9867 auto x = mousexy.first;
9868 auto y = mousexy.second;
9869 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
9870 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
9871 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
9872 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
9873 int32_t cx=(x-startx)/(16*mapscreen_single_scale);
9874 int32_t cy=(y-starty)/(16*mapscreen_single_scale);
9875 ComboPosition combo_pos = {cx, cy};
9876
9877 if (draw_mode == dm_auto)
9878 {
9879 if (combo_pos != mouse_combo_pos)
9880 combobrushoverride = get_autocombo_floating_cid(combo_pos, false);
9881 }
9882 else
9883 combobrushoverride = -1;
9884
9885 mouse_combo_pos = combo_pos;
9886 update_combobrush();
9887
9888 ++scrolldelay;
9889
9890 bool x_on_list = false;
9891 for(auto q = 0; q < num_combo_cols; ++q)
9892 {
9893 if((x>=combolist[q].x) && (x<combolist[q].x+(combolist[q].xscale*combolist[q].w)))
9894 {
9895 x_on_list = true;
9896 break;
9897 }
9898 }
9899 if(MouseScroll && x_on_list && (key[KEY_LSHIFT] || key[KEY_RSHIFT] || (scrolldelay&3)==0))
9900 {
9901 int32_t test_list=0;
9902
9903 for(test_list=0; test_list<num_combo_cols; ++test_list)
9904 {
9905 if((x>=combolist[test_list].x) && (x<combolist[test_list].x+(combolist[test_list].xscale*combolist[test_list].w)))
9906 {
9907 break;
9908 }
9909 }
9910
9911 if(test_list<num_combo_cols)
9912 {
9913 if(y>=combolist[test_list].y-mouse_scroll_h && y<=combolist[test_list].y && First[test_list])
9914 {
9915 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9916 {
9917 First[test_list]=0;
9918 }
9919 else if(CHECK_CTRL_CMD)
9920 {
9921 First[test_list]-=zc_min(First[test_list],256);
9922 }
9923 else if(key[KEY_ALT] || key[KEY_ALTGR])
9924 {
9925 First[test_list]-=zc_min(First[test_list],(combolist[test_list].w*combolist[test_list].h));
9926 }
9927 else
9928 {
9929 First[test_list]-=zc_min(First[test_list],combolist[test_list].w);
9930 }
9931 }
9932
9933 if(y>=combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)-1 && y<combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)+mouse_scroll_h-1 && First[test_list]<(MAXCOMBOS-(combolist[test_list].w*combolist[test_list].h)))
9934 {
9935 int32_t offset = combolist[test_list].w*combolist[test_list].h;
9936
9937 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9938 {
9939 First[test_list]=MAXCOMBOS-offset;
9940 }
9941 else if(CHECK_CTRL_CMD)
9942 {
9943 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+256);
9944 }
9945 else if(key[KEY_ALT] || key[KEY_ALTGR])
9946 {
9947 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+ offset);
9948 }
9949 else
9950 {
9951 First[test_list] = zc_min(MAXCOMBOS - offset, First[test_list] + combolist[test_list].w);
9952 }
9953 }
9954 }
9955 }
9956
9957 // The screen for this combo_pos, layer 0. Used to access ffcs.
9958 mapscr* scr = Map.Scr(combo_pos);
9959 // The screen for this combo_pos at the CurrentLayer. Could be same as scr.
9960 mapscr* draw_mapscr = scr && CurrentLayer ? Map.Scr(combo_pos, CurrentLayer) : scr;
9961 int c = combo_pos.truncate();
9962 set_active_visible_screen(scr);
9963
9964 //-------------
9965 //tooltip stuff
9966 //-------------
9967 if (active_visible_screen && isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
9968 {
9969 static int mapscr_tooltip_id = ttip_register_id();
9970 bool did_ffttip = false;
9971 int num_ffcs = scr->numFFC();
9972 for(int32_t i=num_ffcs-1; i>=0; i--)
9973 if(scr->ffcs[i].data !=0 && (scr->ffcs[i].layer >= CurrentLayer || (!CurrentLayer && scr->ffcs[i].layer < 0) || (scr->ffcs[i].flags&ffc_overlay)))
9974 {
9975 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
9976 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
9977 int32_t ffw = scr->ffTileWidth(i)*16;
9978 int32_t ffh = scr->ffTileHeight(i)*16;
9979 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
9980 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
9981
9982 if(cx2 >= ffx && cx2 < ffx+ffw && cy2 >= ffy && cy2 < ffy+ffh)
9983 {
9984 // FFC tooltip
9985 if(tooltip_current_ffc != i)
9986 {
9987 clear_tooltip();
9988 }
9989
9990 tooltip_current_ffc = i;
9991 char msg[1024] = {0};
9992 auto& ff = scr->ffcs[i];
9993 sprintf(msg,"FFC: %d Combo: %d\nCSet: %d Type: %s\nScript: %s",
9994 i+1, ff.data,ff.data,
9995 combo_class_buf[combobuf[ff.data].type].name,
9996 (ff.script<=0 ? "(None)" : ffcmap[ff.script-1].scriptname.substr(0,400).c_str()));
9997 ttip_install(mapscr_tooltip_id, msg, startxint+(ffx*mapscreen_single_scale), startyint+(ffy*mapscreen_single_scale), ffw*mapscreen_single_scale, ffh*mapscreen_single_scale, x, y);
9998 did_ffttip = true;
9999 break;
10000 }
10001 }
10002 if(!did_ffttip)
10003 {
10004 if(unsigned(c) < 176 && draw_mapscr && !gui_mouse_b())
10005 {
10006 int cid = draw_mapscr->data[c];
10007 newcombo const& cmb = combobuf[cid];
10008 std::ostringstream oss;
10009 int cs = draw_mapscr->cset[c];
10010 int sflag = draw_mapscr->sflag[c];
10011 oss << "Pos: " << c
10012 << "\nCombo: " << cid
10013 << "\nCSet: " << cs;
10014 if(sflag || cmb.flag)
10015 oss << "\nFlags: " << sflag << ", " << (int)cmb.flag;
10016 if(cmb.type)
10017 oss << "\nCombo type: " << combo_class_buf[cmb.type].name;
10018 if(cmb.label[0])
10019 oss << "\nLabel: " << cmb.label;
10020 ttip_install(mapscr_tooltip_id, oss.str().c_str(), startxint+(cx*16*mapscreen_single_scale), startyint+(cy*16*mapscreen_single_scale), 16*mapscreen_single_scale, 16*mapscreen_single_scale, x, y);
10021 }
10022 }
10023 }
10024
10025 {
10026 size_and_pos* squares[4] = {&itemsqr_pos,&stairsqr_pos,&warparrival_pos,&flagsqr_pos};
10027 for(int32_t j=0; j<4; j++)
10028 {
10029 auto& square = *squares[j];
10030 if(square.rect(x,y))
10031 {
10032 char msg[160];
10033 sprintf(msg,
10034 j==0 ? "Item Location" :
10035 j==1 ? "Stairs Secret\nTriggered when a Trigger Push Block is pushed." :
10036 j==2 ? "Arrival Square\nPlayer's location when they begin/resume the game." :
10037 "Combo Flags");
10038 update_tooltip(x,y,square,msg);
10039 }
10040 }
10041
10042 // Warp Returns
10043 for(int32_t j=0; j<4; j++)
10044 {
10045 size_and_pos& wret = warpret_pos[j];
10046 if(wret.rect(x,y))
10047 {
10048 char msg[160];
10049 sprintf(msg,"Warp Return Square %c\nPlayer's destination after warping to this screen.",(char)('A'+j));
10050 update_tooltip(x,y,wret,msg);
10051 }
10052 }
10053
10054 // Enemies
10055 if(enemy_prev_pos.rect(x,y))
10056 {
10057 char msg[160];
10058 sprintf(msg,"Enemies that appear on this screen.");
10059 update_tooltip(x,y,enemy_prev_pos,msg);
10060 }
10061
10062 int32_t cmd = commands_list.rectind(x,y);
10063 if(cmd > -1)
10064 {
10065 update_tooltip(x,y,commands_list.subsquare(cmd),
10066 fmt::format("Fav Command {}: {}\n{}", cmd,
10067 get_hotkey_name(favorite_commands[cmd]),
10068 get_hotkey_helptext(favorite_commands[cmd])).c_str());
10069 }
10070 }
10071
10072 if(draw_mode==dm_alias)
10073 {
10074 for(int32_t j=0; j<num_combo_cols; ++j)
10075 {
10076 auto& sqr = comboaliaslist[j];
10077 auto ind = sqr.rectind(x,y);
10078 if(ind > -1)
10079 {
10080 auto c2=ind+combo_alistpos[j];
10081 char msg[80];
10082 sprintf(msg, "Combo alias %d", c2);
10083 update_tooltip(x,y,sqr.subsquare(ind), msg);
10084 }
10085 }
10086 }
10087 else if(draw_mode==dm_cpool)
10088 {
10089 for(int32_t j=0; j<num_combo_cols; ++j)
10090 {
10091 auto& sqr = comboaliaslist[j];
10092 auto ind = sqr.rectind(x,y);
10093 if(ind > -1)
10094 {
10095 auto c2=ind+combo_pool_listpos[j];
10096 char msg[80];
10097 sprintf(msg, "Combo Pool %d", c2);
10098 update_tooltip(x,y,sqr.subsquare(ind), msg);
10099 }
10100 }
10101 if(cpool_prev_visible && combopool_prevbtn.rect(x,y))
10102 {
10103 if(do_layer_button_reset(combopool_prevbtn.x,combopool_prevbtn.y,
10104 combopool_prevbtn.w,combopool_prevbtn.h,
10105 weighted_cpool ? "Weighted" : "Unweighted",0,true))
10106 {
10107 weighted_cpool = !weighted_cpool;
10108 }
10109 }
10110 }
10111 else if (draw_mode == dm_auto)
10112 {
10113 for (int32_t j = 0; j < num_combo_cols; ++j)
10114 {
10115 auto& sqr = comboaliaslist[j];
10116 auto ind = sqr.rectind(x, y);
10117 if (ind > -1)
10118 {
10119 auto c2 = ind + combo_auto_listpos[j];
10120 char msg[80];
10121 sprintf(msg, "Auto Combo %d", c2);
10122 update_tooltip(x, y, sqr.subsquare(ind), msg);
10123 }
10124 }
10125 }
10126 else
10127 {
10128 if(combo_preview.rect(x,y))
10129 {
10130 auto str = "Combo Colors:\n"+get_combo_colornames(Combo,CSet);
10131 update_tooltip(x,y,combo_preview,str.c_str());
10132 }
10133 else if(comboprev_buf[0] && combo_preview_text1.rect(x,y))
10134 {
10135 update_tooltip(x,y,combo_preview_text1,comboprev_buf);
10136 }
10137 else if(comboprev_buf2[0] && combo_preview_text2.rect(x,y))
10138 {
10139 update_tooltip(x,y,combo_preview_text2,comboprev_buf2);
10140 }
10141 else for(int32_t j=0; j<num_combo_cols; ++j)
10142 {
10143 auto& sqr = combolist[j];
10144 auto ind = sqr.rectind(x,y);
10145 if(ind > -1)
10146 {
10147 int32_t c2=ind+First[j];
10148 std::ostringstream oss;
10149 newcombo const& cmb = combobuf[c2];
10150 oss << "Combo " << c2 << ": " << combo_class_buf[cmb.type].name;
10151 if(cmb.flag != 0)
10152 oss << "\nInherent flag: " << ZI.getMapFlagName(cmb.flag);
10153 if(!cmb.label.empty())
10154 oss << "\nLabel: " << cmb.label;
10155
10156 update_tooltip(x,y,sqr.subsquare(ind), oss.str().c_str());
10157 }
10158 }
10159 }
10160
10161 if (favorites_list.rect(x, y))
10162 {
10163 int32_t f = favorites_list.rectind(x, y);
10164 int32_t row = f / favorites_list.w;
10165 int32_t col = f % favorites_list.w;
10166 f = (row * FAVORITECOMBO_PER_ROW) + col;
10167
10168 auto& sqr = favorites_list.subsquare(col, row);
10169
10170 char buf[180];
10171 if (favorite_combos[f] == -1)
10172 sprintf(buf, "Fav Combo %d\nEmpty", f);
10173 else
10174 {
10175 switch (favorite_combo_modes[f])
10176 {
10177 case dm_alias:
10178 sprintf(buf, "Fav Combo %d\nAlias %d", f, favorite_combos[f]);
10179 break;
10180 case dm_cpool:
10181 sprintf(buf, "Fav Combo %d\nPool %d", f, favorite_combos[f]);
10182 break;
10183 case dm_auto:
10184 sprintf(buf, "Fav Combo %d\nAutocombo %d", f, favorite_combos[f]);
10185 break;
10186 default:
10187 sprintf(buf, "Fav Combo %d\nCombo %d", f, favorite_combos[f]);
10188 }
10189 }
10190 update_tooltip(x, y, sqr, buf);
10191 }
10192
10193 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
10194 auto ind = real_mini.rectind(x,y);
10195 if(ind > -1)
10196 {
10197 char buf[80];
10198 sprintf(buf,"0x%02X (%d)", ind, ind);
10199 ttip_install(minimap_tooltip_id, buf, real_mini.subsquare(ind), real_mini.x+real_mini.tw(), real_mini.y-16);
10200 ttip_set_highlight_thickness(minimap_tooltip_id, zoomed_minimap ? 2 : 1);
10201 // Make sure always above the other tooltip items to the right of the map (even in big map mode).
10202 ttip_set_z_index(minimap_tooltip_id, 100);
10203 ttip_clear_timer();
10204 }
10205 else
10206 {
10207 ttip_uninstall(minimap_tooltip_id);
10208 }
10209
10210 // Mouse clicking stuff
10211 int real_mb = gui_mouse_b();
10212 int mb = real_mb & ~mouse_down; //Only handle clicks that have not been handled already
10213 auto mz = mouse_z;
10214 bool lclick = mb&1;
10215 bool rclick = mb&2;
10216
10217 FONT* tfont = font;
10218 if(zoomed_minimap)
10219 {
10220 if((lclick||rclick) && !minimap_zoomed.rect(x,y))
10221 {
10222 // 'Clicked off'
10223 mmap_set_zoom(false);
10224 goto domouse_doneclick;
10225 }
10226 }
10227
10228 if(real_mb==0)
10229 {
10230 mouse_down = 0;
10231 canfill=true;
10232 }
10233 else if(lclick || rclick)
10234 {
10235 //on the minimap
10236 if(real_mini.rect(x,y))
10237 {
10238 if(lclick)
10239 select_scr();
10240 else if(rclick && !(mouse_down&2))
10241 {
10242 mmap_set_zoom(!zoomed_minimap);
10243 }
10244 goto domouse_doneclick;
10245 }
10246
10247 if(zoomed_minimap && minimap_zoomed.rect(x,y))
10248 goto domouse_doneclick; //Eat clicks
10249
10250 //on the map tabs
10251 font = get_custom_font(CFONT_GUI);
10252 for(int32_t btn=0; btn<mappage_count; ++btn)
10253 {
10254 if (btn == current_mappage) continue;
10255 char tbuf[15];
10256 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
10257 auto& sqr = map_page_bar[btn];
10258 if(sqr.rect(x,y))
10259 {
10260 if(do_layer_button_reset(sqr.x,sqr.y,sqr.w,sqr.h,tbuf,(btn==current_mappage?D_SELECTED:0)))
10261 {
10262 draw_layer_button(screen, sqr.x,sqr.y,sqr.w,sqr.h,tbuf,D_SELECTED);
10263
10264 if (lclick)
10265 {
10266 map_page[current_mappage].map=Map.getCurrMap();
10267 map_page[current_mappage].screen=Map.getCurrScr();
10268 current_mappage=btn;
10269 Map.setCurrMap(map_page[current_mappage].map);
10270 Map.setCurrScr(map_page[current_mappage].screen);
10271 rebuild_trans_table(); //Woo
10272 }
10273 else if (rclick)
10274 {
10275 map_page[btn].map = 0;
10276 map_page[btn].screen = 0;
10277 }
10278 }
10279 goto domouse_doneclick;
10280 }
10281 }
10282
10283 if(compactbtn.rect(x,y))
10284 {
10285 if(do_text_button(compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact"));
10286 toggle_is_compact();
10287 goto domouse_doneclick;
10288 }
10289
10290 if(!zoom_in_btn_disabled && zoominbtn.rect(x,y))
10291 {
10292 if(do_text_button(zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+"))
10293 change_mapscr_zoom(-1);
10294 goto domouse_doneclick;
10295 }
10296
10297 if(!zoom_out_btn_disabled && zoomoutbtn.rect(x,y))
10298 {
10299 if(do_text_button(zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-"))
10300 change_mapscr_zoom(1);
10301 goto domouse_doneclick;
10302 }
10303
10304 font = get_zc_font(font_lfont_l);
10305 if(combo_merge_btn.rect(x,y))
10306 {
10307 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
10308 if(do_text_button(combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<"))
10309 {
10310 toggle_merged_mode();
10311 }
10312 goto domouse_doneclick;
10313 }
10314
10315 if(favorites_zoombtn.rect(x,y))
10316 {
10317 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
10318 if(do_text_button(favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+"))
10319 {
10320 toggle_favzoom_mode();
10321 }
10322 goto domouse_doneclick;
10323 }
10324 else if(favorites_x.rect(x,y))
10325 {
10326 if(do_text_button(favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X"))
10327 {
10328 if (alert_confirm("Clear Favorite Combos", "Are you sure you want"
10329 " to clear all favorite combos?"))
10330 {
10331 for(auto q = 0; q < MAXFAVORITECOMBOS; ++q)
10332 {
10333 favorite_combos[q] = -1;
10334 favorite_combo_modes[q] = dm_normal;
10335 }
10336 mark_save_dirty();
10337 refresh(rFAVORITES);
10338 }
10339 }
10340 goto domouse_doneclick;
10341 }
10342 else if(favorites_infobtn.rect(x,y))
10343 {
10344 if(do_text_button(favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?"))
10345 {
10346 InfoDialog("Favorite Combos",
10347 "On LClick (empty): Sets clicked favorite to the current combo."
10348 "\nOn LClick: Sets current combo to clicked favorite."
10349 "\nShift+LClick: Sets clicked favorite to current combo."
10350 "\nCtrl+LClick: Clears clicked favorite."
10351 "\nAlt+LClick: Scrolls to clicked favorite."
10352 "\nRClick: Opens context menu."
10353 "\n\nClick the Page buttons (<-/->) to cycle between pages (RClick to jump to a page)"
10354 "\nClick the Zoom button (+/-) to toggle zoom level."
10355 "\nClick the X button to clear all favorite combos.").show();
10356 }
10357 goto domouse_doneclick;
10358 }
10359 else if(favorites_pgleft.rect(x,y))
10360 {
10361 if (do_text_button(favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-"))
10362 {
10363 if (rclick)
10364 {
10365 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10366 FavoriteComboPage = vbound(*val-1, 0, 8);
10367 }
10368 else
10369 FavoriteComboPage = FavoriteComboPage == 0 ? 8 : --FavoriteComboPage;
10370 reload_zq_gui();
10371 }
10372 goto domouse_doneclick;
10373 }
10374 else if(favorites_pgright.rect(x,y))
10375 {
10376 if (do_text_button(favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->"))
10377 {
10378 if (rclick)
10379 {
10380 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10381 FavoriteComboPage = vbound(*val-1, 0, 8);
10382 }
10383 else
10384 FavoriteComboPage = FavoriteComboPage == 8 ? 0 : ++FavoriteComboPage;
10385 reload_zq_gui();
10386 }
10387 goto domouse_doneclick;
10388 }
10389
10390 if(commands_zoombtn.rect(x,y))
10391 {
10392 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
10393 if(do_text_button(commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+"))
10394 {
10395 toggle_cmdzoom_mode();
10396 }
10397 goto domouse_doneclick;
10398 }
10399 else if(commands_x.rect(x,y))
10400 {
10401 if(do_text_button(commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X"))
10402 {
10403 if (alert_confirm("Clear Favorite Commands", "Are you sure you want"
10404 " to clear all favorite commands?"))
10405 {
10406 for(auto q = 0; q < MAXFAVORITECOMMANDS; ++q)
10407 write_fav_command(q,0);
10408 refresh(rFAVORITES);
10409 }
10410 }
10411 goto domouse_doneclick;
10412 }
10413 else if(commands_infobtn.rect(x,y))
10414 {
10415 if(do_text_button(commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?"))
10416 {
10417 InfoDialog("Favorite Commands",
10418 "On LClick (empty): Choose a favorite command"
10419 "\nOn LClick: Runs the favorite command"
10420 "\nShift+Click: Choose a favorite command"
10421 "\nRClick: Choose a favorite command"
10422 "\nCtrl+Click: Clears clicked command"
10423 "\nAlt+Click: Shows info on the favorite command"
10424 "\n\nClick the Zoom button (+/-) to toggle zoom level"
10425 "\nClick the X button to clear all favorite commands").show();
10426 }
10427 goto domouse_doneclick;
10428 }
10429 font=tfont;
10430
10431 // On the layer panel
10432 font = get_custom_font(CFONT_GUI);
10433 for(int32_t i=0; i<=6; ++i)
10434 {
10435 int32_t spacing_offs = is_compact ? 2 : 10;
10436 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
10437 int32_t ry = layer_panel.y;
10438
10439 if (i != CurrentLayer && (i == 0 || mapscreen_valid_layers[i - 1]) && isinRect(x,y,rx,ry,rx+layerpanel_buttonwidth-1,ry+layerpanel_buttonheight-1))
10440 {
10441 char tbuf[15];
10442
10443 if (Map.getViewSize() > 1)
10444 {
10445 sprintf(tbuf, "%d", i);
10446 }
10447 else if (i != 0 && mapscreen_valid_layers[i - 1])
10448 {
10449 if (is_compact)
10450 {
10451 sprintf(tbuf, "%s%d %d:%02X",
10452 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10453 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10454 }
10455 else
10456 {
10457 sprintf(tbuf, "%s%d (%d:%02X)",
10458 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10459 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10460 }
10461 }
10462 else
10463 {
10464 sprintf(tbuf, "%d", i);
10465 }
10466
10467 if(do_text_button(rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf))
10468 {
10469 CurrentLayer = i;
10470 goto domouse_doneclick;
10471 }
10472 }
10473
10474 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
10475 if(isinRect(x,y,rx+layerpanel_buttonwidth+1,ry+cbyofs,rx+layerpanel_buttonwidth+1+layerpanel_checkbox_wid-1,ry+2+layerpanel_checkbox_hei-1))
10476 {
10477 do_checkbox(screen,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]);
10478 goto domouse_doneclick;
10479 }
10480 }
10481 font=tfont;
10482
10483 //Uses lclick/rclick separately
10484
10485 //on the map screen
10486 if(isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
10487 {
10488 if (lclick)
10489 {
10490 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
10491 }
10492
10493 if (draw_mode == dm_auto)
10494 {
10495 if (CHECK_CTRL_CMD)
10496 {
10497 if (canfill)
10498 {
10499 switch (fill_type)
10500 {
10501 case 0:
10502 flood();
10503 break;
10504
10505 case 1:
10506 fill_4();
10507 break;
10508
10509 case 2:
10510 fill_8();
10511 break;
10512
10513 case 3:
10514 fill2_4();
10515 break;
10516
10517 case 4:
10518 fill2_8();
10519 break;
10520 }
10521
10522 canfill = false;
10523 }
10524 }
10525 else
10526 draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10527 }
10528 else if (scr && lclick)
10529 {
10530 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10531 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10532
10533 // Move items
10534 if (scr->hasitem && active_visible_screen)
10535 {
10536 int32_t ix = scr->itemx + active_visible_screen->dx * 256;
10537 int32_t iy = scr->itemy + active_visible_screen->dy * 176;
10538
10539 if(cx2 >= ix && cx2 < ix+16 && cy2 >= iy && cy2 < iy+16)
10540 doxypos(scr->itemx, scr->itemy, 11, SNAP_HALF, SNAP_NONE, true, 0, 0, 16, 16);
10541 }
10542
10543 // Move FFCs
10544 int num_ffcs = scr->numFFC();
10545 for(int32_t i=num_ffcs-1; i>=0; i--)
10546 if(scr->ffcs[i].data !=0 && (scr->ffcs[i].layer >= CurrentLayer || (!CurrentLayer && scr->ffcs[i].layer < 0) || (scr->ffcs[i].flags&ffc_overlay)))
10547 {
10548 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10549 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10550
10551 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10552 {
10553 moveffc(i, cx2, cy2);
10554 break;
10555 }
10556 }
10557
10558 if(key[KEY_ALT]||key[KEY_ALTGR])
10559 {
10560 if (!draw_mapscr) return;
10561
10562 Combo=draw_mapscr->data[c];
10563 if(AutoBrush)
10564 BrushWidth = BrushHeight = 1;
10565 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
10566 CSet=draw_mapscr->cset[c];
10567 if(CHECK_CTRL_CMD)
10568 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
10569 }
10570 else if(CHECK_CTRL_CMD)
10571 {
10572 if(canfill)
10573 {
10574 switch(fill_type)
10575 {
10576 case 0:
10577 flood();
10578 break;
10579
10580 case 1:
10581 fill_4();
10582 break;
10583
10584 case 2:
10585 fill_8();
10586 break;
10587
10588 case 3:
10589 fill2_4();
10590 break;
10591
10592 case 4:
10593 fill2_8();
10594 break;
10595 }
10596
10597 canfill=false;
10598 }
10599 }
10600 else draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10601 }
10602 else if (scr && rclick)
10603 {
10604 ComboBrushPause=1;
10605 refresh(rMAP);
10606 restore_mouse();
10607 ComboBrushPause=0;
10608
10609 bool clickedffc = false;
10610
10611 // FFC right-click menu
10612 // This loop also serves to find the free ffc with the smallest slot number.
10613 int num_ffcs = scr->numFFC();
10614 uint32_t earliestfreeffc = num_ffcs;
10615 for(int32_t i=num_ffcs-1; i>=0; i--)
10616 {
10617 auto data = scr->ffcs[i].data;
10618 if(data==0)
10619 {
10620 if(i < earliestfreeffc)
10621 earliestfreeffc = i;
10622 continue;
10623 }
10624
10625 if(clickedffc || !(scr->valid&mVALID))
10626 continue;
10627
10628 if(data!=0 && (scr->ffcs[i].layer >= CurrentLayer || (!CurrentLayer && scr->ffcs[i].layer < 0) || (scr->ffcs[i].flags&ffc_overlay)))
10629 {
10630 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10631 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10632 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10633 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10634
10635 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10636 {
10637 auto& ffc = scr->ffcs[i];
10638 NewMenu rcmenu
10639 {
10640 { "Copy FFC", [&](){Map.CopyFFC(active_visible_screen->screen, i);} },
10641 { "Paste FFC data", [&]()
10642 {
10643 if(alert_confirm("Confirm Paste", "Really replace the FFC with"
10644 " the data of the copied FFC?"))
10645 {
10646 auto set_ffc_data = Map.getCopyFFCData();
10647 set_ffc_data.x = scr->ffcs[i].x;
10648 set_ffc_data.y = scr->ffcs[i].y;
10649 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10650 }
10651 }, nullopt, Map.getCopyFFC() < 0 ? MFL_DIS : 0 },
10652 { "Edit FFC", [&](){call_ffc_dialog(i, active_visible_screen->scr, active_visible_screen->screen);} },
10653 { "Clear FFC", [&]()
10654 {
10655 if (alert_confirm("Confirm Clear", "Really clear this Freeform Combo?"))
10656 {
10657 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, {
10658 .x = 0,
10659 .y = 0,
10660 .vx = 0,
10661 .vy = 0,
10662 .ax = 0,
10663 .ay = 0,
10664 .data = 0,
10665 .cset = 0,
10666 .delay = 0,
10667 .link = 0,
10668 .script = 0,
10669 .tw = 1,
10670 .th = 1,
10671 .ew = 16,
10672 .eh = 16,
10673 .flags = ffc_none,
10674 .initd = 0,
10675 });
10676 mark_save_dirty();
10677 }
10678 } },
10679 { "Snap to Grid", [&]()
10680 {
10681 int oldffx = scr->ffcs[i].x.getInt();
10682 int oldffy = scr->ffcs[i].y.getInt();
10683 int pos = COMBOPOS(oldffx,oldffy);
10684 int newffy = COMBOY(pos);
10685 int newffx = COMBOX(pos);
10686
10687 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
10688 set_ffc_data.x = newffx;
10689 set_ffc_data.y = newffy;
10690 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10691
10692 mark_save_dirty();
10693 } },
10694 {},
10695 { "Select Combo", [&]()
10696 {
10697 Combo = ffc.data;
10698 } },
10699 { "Scroll to Combo", [&]()
10700 {
10701 First[current_combolist] = scrollto_cmb(ffc.data);
10702 } },
10703 { "Open Combo Page", [&]()
10704 {
10705 open_combo_pages(ffc.data);
10706 } },
10707 { "Edit Combo", [&]()
10708 {
10709 edit_combo(ffc.data,true,ffc.cset);
10710 } },
10711 };
10712 rcmenu.pop(x, y);
10713 clickedffc = true;
10714 break;
10715 }
10716 }
10717 }
10718
10719 // Combo right-click menu
10720 if(!clickedffc)
10721 {
10722 int warpindex = Map.warpindex(scr->data[c]);
10723 string txt_twarp_follow, txt_twarp_edit, txt_ffc_edit, txt_ffc_paste;
10724 bool show_ffcs = earliestfreeffc < MAXFFCS;
10725 bool dis_paste_ffc = Map.getCopyFFC() < 0;
10726 bool show_warps = warpindex > -1;
10727 bool show_warpback = Map.has_warpback();
10728 // FFC-specific options
10729 if(earliestfreeffc < MAXFFCS)
10730 {
10731 txt_ffc_edit = fmt::format("Edit New FFC {}",earliestfreeffc+1);
10732 if(Map.getCopyFFC()>-1)
10733 txt_ffc_paste = fmt::format("Paste FFC as FFC {}",earliestfreeffc+1);
10734 else
10735 txt_ffc_paste = "Paste FFC";
10736 }
10737
10738 if(warpindex > -1)
10739 {
10740 char letter = warpindex==4 ? 'R' : 'A'+warpindex;
10741 txt_twarp_follow = fmt::format("Follow Tile Warp {}",letter);
10742 txt_twarp_edit = fmt::format("Edit Tile Warp {}",letter);
10743 }
10744
10745 NewMenu draw_rc_menu
10746 {
10747 { "Select Combo", [&]()
10748 {
10749 Combo = draw_mapscr->data[c];
10750 if(AutoBrush)
10751 BrushWidth = BrushHeight = 1;
10752 }, nullopt, !draw_mapscr },
10753 { "Scroll to Combo", [&]()
10754 {
10755 First[current_combolist] = scrollto_cmb(draw_mapscr->data[c]);
10756 }, nullopt, !draw_mapscr },
10757 { "Open Combo Page", [&]()
10758 {
10759 open_combo_pages(draw_mapscr->data[c]);
10760 }, nullopt, !draw_mapscr },
10761 { "Edit Combo", [&]()
10762 {
10763 edit_combo(draw_mapscr->data[c],true,draw_mapscr->cset[c]);
10764 }, nullopt, !draw_mapscr },
10765 {},
10766 { "Replace All", [&](){replace(combo_pos);} },
10767 { "Draw Block", &draw_block_menu },
10768 { "Brush Settings ", &brush_menu },
10769 { "Set Fill Type ", &fill_menu },
10770 };
10771 if(show_warps || show_warpback)
10772 {
10773 draw_rc_menu.add_sep();
10774 if(show_warpback)
10775 draw_rc_menu.add({ "Warp Back", [&](){Map.warpback();} });
10776 if(show_warps)
10777 {
10778 draw_rc_menu.add({ txt_twarp_follow, [&](){follow_twarp(warpindex);} });
10779 draw_rc_menu.add({ txt_twarp_edit, [&](){edit_twarp(warpindex);} });
10780 }
10781 }
10782 if(show_ffcs)
10783 {
10784 draw_rc_menu.add_sep();
10785 draw_rc_menu.add({ txt_ffc_edit, [&]()
10786 {
10787 ffdata tempdat;
10788 // x, y are ints on ffdata (but ffc x, y are zfix), so *10000
10789 tempdat.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256) * 10000;
10790 tempdat.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176) * 10000;
10791 tempdat.data = Combo;
10792 tempdat.cset = CSet;
10793 if (SmartFFCPlacement)
10794 {
10795 tempdat.layer = CurrentLayer;
10796 SETFLAG(tempdat.flags, ffc_solid, (combobuf[Combo].walk & 0xF) == 0xF);
10797 }
10798 call_ffc_dialog(earliestfreeffc, tempdat, active_visible_screen->scr, active_visible_screen->screen);
10799 } });
10800 draw_rc_menu.add({ txt_ffc_paste, [&]()
10801 {
10802 auto set_ffc_data = Map.getCopyFFCData();
10803 set_ffc_data.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256);
10804 set_ffc_data.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176);
10805 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, earliestfreeffc, set_ffc_data);
10806 }, nullopt, dis_paste_ffc });
10807 }
10808 draw_rc_menu.add_sep();
10809 draw_rc_menu.add({ "Screen", &rc_menu_screen });
10810 draw_rc_menu.pop(x,y);
10811 }
10812 }
10813 goto domouse_doneclick;
10814 }
10815
10816 //on the drawing mode button
10817 font = get_custom_font(CFONT_GUI);
10818 if(drawmode_btn.rect(x,y))
10819 {
10820 if(lclick)
10821 {
10822 if(do_text_button(drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode]))
10823 onDrawingMode();
10824 }
10825 else if(rclick)
10826 drawing_mode_menu.pop(x,y);
10827 goto domouse_doneclick;
10828 }
10829 font=tfont;
10830
10831 //Squares
10832 //
10833 set_active_visible_screen(Map.CurrScr());
10834 {
10835 if(squarepanel_swap_btn.rect(x,y))
10836 {
10837 toggle_compact_sqr_mode();
10838 goto domouse_doneclick;
10839 }
10840 if(squarepanel_up_btn.rect(x,y))
10841 {
10842 cycle_compact_sqr(false);
10843 goto domouse_doneclick;
10844 }
10845 if(squarepanel_down_btn.rect(x,y))
10846 {
10847 cycle_compact_sqr(true);
10848 goto domouse_doneclick;
10849 }
10850
10851 bool do_dummyxy = false;
10852 bool dummymode = key[KEY_LSHIFT] || key[KEY_RSHIFT];
10853
10854 if(itemsqr_pos.rect(x,y))
10855 {
10856 if(dummymode) do_dummyxy = true;
10857 else
10858 {
10859 onItem();
10860
10861 if(!rclick && Map.CurrScr()->hasitem)
10862 doxypos(Map.CurrScr()->itemx,Map.CurrScr()->itemy,11,SNAP_HALF,SNAP_NONE);
10863 goto domouse_doneclick;
10864 }
10865 }
10866
10867 if(stairsqr_pos.rect(x,y))
10868 {
10869 if(dummymode) do_dummyxy = true;
10870 else
10871 {
10872 doxypos(Map.CurrScr()->stairx,Map.CurrScr()->stairy,14,SNAP_WHOLE);
10873 goto domouse_doneclick;
10874 }
10875 }
10876
10877 if(warparrival_pos.rect(x,y))
10878 {
10879 if(dummymode) do_dummyxy = true;
10880 else
10881 {
10882 if(get_qr(qr_NOARRIVALPOINT))
10883 {
10884 info_dsa("Arrival Square",
10885 "The arrival square cannot be used unless the QR 'Use Warp Return "
10886 "Points Only' under 'Quest->Options->Combos' is disabled."
10887 "\nGenerally, this square only exists for compatibility purposes, and is not used"
10888 " in creating new quests.",
10889 "dsa_warparrival");
10890 }
10891 else doxypos(Map.CurrScr()->warparrivalx,Map.CurrScr()->warparrivaly,10,SNAP_HALF,SNAP_NONE);
10892 goto domouse_doneclick;
10893 }
10894 }
10895
10896 if(flagsqr_pos.rect(x,y))
10897 {
10898 if(dummymode) do_dummyxy = true;
10899 else
10900 {
10901 onFlags();
10902 goto domouse_doneclick;
10903 }
10904 }
10905
10906 for(auto q = 0; q < 4; ++q)
10907 {
10908 if(warpret_pos[q].rect(x,y))
10909 {
10910 if(dummymode) do_dummyxy = true;
10911 else
10912 {
10913 doxypos(Map.CurrScr()->warpreturnx[q],Map.CurrScr()->warpreturny[q],9,SNAP_HALF,SNAP_NONE);
10914 goto domouse_doneclick;
10915 }
10916 }
10917 }
10918
10919 if(enemy_prev_pos.rect(x,y))
10920 {
10921 if(dummymode) do_dummyxy = true;
10922 else
10923 {
10924 onEnemies();
10925 goto domouse_doneclick;
10926 }
10927 }
10928
10929 if(do_dummyxy)
10930 {
10931 byte x = 0, y = 0;
10932 showxypos_dummy = true;
10933 doxypos(x,y,13,SNAP_HALF,SNAP_NONE);
10934 goto domouse_doneclick;
10935 }
10936 }
10937
10938 if(draw_mode==dm_alias)
10939 {
10940 for(int32_t j=0; j<num_combo_cols; ++j)
10941 {
10942 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10943 {
10944 scrollup(j);
10945 goto domouse_doneclick;
10946 }
10947 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10948 {
10949 scrolldown(j);
10950 goto domouse_doneclick;
10951 }
10952 else if(comboaliaslist[j].rect(x,y))
10953 {
10954 select_comboa(j);
10955
10956 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10957 popup_cpane_rc(x, y);
10958 goto domouse_doneclick;
10959 }
10960 }
10961 }
10962 else if(draw_mode==dm_cpool)
10963 {
10964 for(int32_t j=0; j<num_combo_cols; ++j)
10965 {
10966 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10967 {
10968 scrollup(j);
10969 goto domouse_doneclick;
10970 }
10971 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10972 {
10973 scrolldown(j);
10974 goto domouse_doneclick;
10975 }
10976 else if(comboaliaslist[j].rect(x,y))
10977 {
10978 select_combop(j);
10979
10980 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10981 popup_cpane_rc(x, y);
10982 goto domouse_doneclick;
10983 }
10984 }
10985 }
10986 else if (draw_mode == dm_auto)
10987 {
10988 for (int32_t j = 0; j < num_combo_cols; ++j)
10989 {
10990 if (combolistscrollers[j].rectind(x, y) == 0 && !mouse_down)
10991 {
10992 scrollup(j);
10993 goto domouse_doneclick;
10994 }
10995 else if (combolistscrollers[j].rectind(x, y) == 1 && !mouse_down)
10996 {
10997 scrolldown(j);
10998 goto domouse_doneclick;
10999 }
11000 else if (comboaliaslist[j].rect(x, y))
11001 {
11002 select_autocombo(j);
11003
11004 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
11005 popup_cpane_rc(x, y);
11006 goto domouse_doneclick;
11007 }
11008 }
11009 }
11010 else
11011 {
11012 for(int32_t j=0; j<num_combo_cols; ++j)
11013 {
11014 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
11015 {
11016 scrollup(j);
11017 goto domouse_doneclick;
11018 }
11019 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
11020 {
11021 scrolldown(j);
11022 goto domouse_doneclick;
11023 }
11024 else if(combolist[j].rect(x,y))
11025 {
11026 select_combo(j);
11027
11028 if(rclick && combolist[j].rect(gui_mouse_x(),gui_mouse_y()))
11029 popup_cpane_rc(x, y);
11030 goto domouse_doneclick;
11031 }
11032 }
11033 }
11034
11035 //on the favorites list
11036 if(favorites_list.rect(x,y))
11037 {
11038 if(lclick)
11039 {
11040 int32_t f=favorites_list.rectind(x,y);
11041 int32_t row=f/favorites_list.w;
11042 int32_t col=f%favorites_list.w;
11043 f = (row*FAVORITECOMBO_PER_ROW)+col;
11044 int32_t fp = f + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
11045
11046 bool dmcond = favorite_combos[fp] < 0;
11047 if((key[KEY_LSHIFT] || key[KEY_RSHIFT] || dmcond) && !(CHECK_CTRL_CMD))
11048 {
11049 int32_t tempcb=ComboBrush;
11050 ComboBrush=0;
11051
11052 while(gui_mouse_b())
11053 {
11054 x=gui_mouse_x();
11055 y=gui_mouse_y();
11056
11057 switch(draw_mode)
11058 {
11059 case dm_alias:
11060 if (favorite_combos[fp] != combo_apos || favorite_combo_modes[fp] != dm_alias)
11061 {
11062 favorite_combo_modes[fp] = dm_alias;
11063 favorite_combos[fp] = combo_apos;
11064 mark_save_dirty();
11065 }
11066 break;
11067 case dm_cpool:
11068 if (favorite_combos[fp] != combo_pool_pos || favorite_combo_modes[fp] != dm_cpool)
11069 {
11070 favorite_combo_modes[fp] = dm_cpool;
11071 favorite_combos[fp] = combo_pool_pos;
11072 mark_save_dirty();
11073 }
11074 break;
11075 case dm_auto:
11076 if (favorite_combos[fp] != combo_auto_pos || favorite_combo_modes[fp] != dm_auto)
11077 {
11078 favorite_combo_modes[fp] = dm_auto;
11079 favorite_combos[fp] = combo_auto_pos;
11080 mark_save_dirty();
11081 }
11082 break;
11083 default:
11084 if (favorite_combos[fp] != Combo || favorite_combo_modes[fp] != dm_normal)
11085 {
11086 if (BrushWidth > 1 || BrushHeight > 1)
11087 {
11088 add_favorite_combo_block(f, Combo, key[KEY_LSHIFT] || key[KEY_RSHIFT]);
11089 break;
11090 }
11091 favorite_combo_modes[fp] = dm_normal;
11092 favorite_combos[fp] = Combo;
11093 mark_save_dirty();
11094 }
11095 }
11096
11097 custom_vsync();
11098 refresh(rALL | rFAVORITES);
11099 }
11100
11101 ComboBrush=tempcb;
11102 }
11103 else if(CHECK_CTRL_CMD)
11104 {
11105 int32_t tempcb=ComboBrush;
11106 ComboBrush=0;
11107
11108 while(gui_mouse_b())
11109 {
11110 x=gui_mouse_x();
11111 y=gui_mouse_y();
11112
11113 if(favorite_combos[fp]!=-1)
11114 {
11115 favorite_combo_modes[fp] = dm_normal;
11116 favorite_combos[fp]=-1;
11117 mark_save_dirty();
11118 }
11119
11120 custom_vsync();
11121 refresh(rALL | rFAVORITES);
11122 }
11123
11124 ComboBrush=tempcb;
11125 }
11126 else if(key[KEY_ALT] || key[KEY_ALTGR])
11127 {
11128 if(select_favorite())
11129 {
11130 switch(favorite_combo_modes[fp])
11131 {
11132 case dm_alias:
11133 combo_alistpos[current_comboalist]=scrollto_alias(combo_apos);
11134 break;
11135 case dm_cpool:
11136 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
11137 break;
11138 case dm_auto:
11139 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
11140 break;
11141 default:
11142 First[current_combolist]=scrollto_cmb(Combo);
11143 }
11144 }
11145 }
11146 else
11147 {
11148 select_favorite();
11149 }
11150 }
11151 else if(rclick)
11152 {
11153 bool valid=select_favorite();
11154
11155 if(valid)
11156 {
11157 int f = favorites_list.rectind(x,y);
11158 int row = f/favorites_list.w;
11159 int col = f%favorites_list.w;
11160 f = (row*FAVORITECOMBO_PER_ROW) + col + (FAVORITECOMBO_PER_PAGE * FavoriteComboPage);
11161 popup_favorites_rc(f, x, y);
11162 }
11163 }
11164 goto domouse_doneclick;
11165 }
11166
11167 //on the commands buttons
11168 int32_t cmd = commands_list.rectind(x,y);
11169 if(cmd > -1)
11170 {
11171 uint hkey = favorite_commands[cmd];
11172 bool shift=(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
11173 bool ctrl=(CHECK_CTRL_CMD);
11174 bool alt=(key[KEY_ALT] || key[KEY_ALTGR]);
11175 bool dis = disabled_hotkey(hkey);
11176 auto& btn = commands_list.subsquare(cmd);
11177 if(!dis||rclick||shift||ctrl||alt)
11178 {
11179 FONT *tfont=font;
11180 font=get_custom_font(CFONT_FAVCMD);
11181 if(do_layer_button_reset(btn.x,btn.y,btn.w,btn.h,
11182 get_hotkey_name(hkey),
11183 selected_hotkey(hkey)?D_SELECTED:0,
11184 true))
11185 {
11186 font=tfont;
11187 if(alt)
11188 {
11189 show_hotkey_info(hkey);
11190 }
11191 else if(ctrl)
11192 {
11193 write_fav_command(cmd,0);
11194 }
11195 else if(rclick || shift || hkey==ZQKEY_NULL_KEY)
11196 {
11197 if(auto newkey = select_fav_command())
11198 write_fav_command(cmd,*newkey);
11199 }
11200 else
11201 {
11202 run_hotkey(hkey);
11203 }
11204 }
11205
11206 font=tfont;
11207 }
11208 goto domouse_doneclick;
11209 }
11210 }
11211
11212 domouse_doneclick:
11213 mouse_down |= mb&3;
11214
11215 if(mouse_z!=0)
11216 {
11217 int32_t z=0;
11218
11219 for(int32_t j=0; j<num_combo_cols; ++j)
11220 {
11221 z=abs(mouse_z);
11222
11223 if(key[KEY_ALT]||key[KEY_ALTGR])
11224 {
11225 z*=combolist[j].h;
11226 }
11227
11228
11229 if(draw_mode == dm_alias)
11230 {
11231 if(comboaliaslist[j].rect(x,y))
11232 {
11233 if(mouse_z<0) //scroll down
11234 {
11235 combo_alistpos[current_comboalist] = zc_min(MAXCOMBOALIASES - comboaliaslist[j].w*comboaliaslist[j].h,
11236 combo_alistpos[current_comboalist]+comboaliaslist[j].w*z);
11237 }
11238 else //scroll up
11239 {
11240 if(combo_alistpos[current_comboalist]>0)
11241 {
11242 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],comboaliaslist[j].w*z);
11243 }
11244 }
11245 goto domouse_donez;
11246 }
11247 }
11248 else if(draw_mode == dm_cpool)
11249 {
11250 if(comboaliaslist[j].rect(x,y))
11251 {
11252 if(mouse_z<0) //scroll down
11253 {
11254 combo_pool_listpos[current_cpoollist] = zc_min(MAXCOMBOPOOLS - comboaliaslist[j].w*comboaliaslist[j].h,
11255 combo_pool_listpos[current_cpoollist]+comboaliaslist[j].w*z);
11256 }
11257 else //scroll up
11258 {
11259 if(combo_pool_listpos[current_cpoollist]>0)
11260 {
11261 combo_pool_listpos[current_cpoollist]-=zc_min(combo_pool_listpos[current_cpoollist],comboaliaslist[j].w*z);
11262 }
11263 }
11264 goto domouse_donez;
11265 }
11266 }
11267 else if (draw_mode == dm_auto)
11268 {
11269 if (comboaliaslist[j].rect(x, y))
11270 {
11271 if (mouse_z < 0) //scroll down
11272 {
11273 combo_auto_listpos[current_cautolist] = zc_min(MAXAUTOCOMBOS - comboaliaslist[j].w * comboaliaslist[j].h,
11274 combo_auto_listpos[current_cautolist] + comboaliaslist[j].w * z);
11275 }
11276 else //scroll up
11277 {
11278 if (combo_auto_listpos[current_cautolist] > 0)
11279 {
11280 combo_auto_listpos[current_cautolist] -= zc_min(combo_auto_listpos[current_cautolist], comboaliaslist[j].w * z);
11281 }
11282 }
11283 goto domouse_donez;
11284 }
11285 }
11286 else
11287 {
11288 if(combolist[j].rect(x,y))
11289 {
11290 if(mouse_z<0) //scroll down
11291 {
11292 First[current_combolist] = zc_min(MAXCOMBOS-combolist[j].w*combolist[j].h,
11293 First[current_combolist] + combolist[j].w*z);
11294 }
11295 else //scroll up
11296 {
11297 if(First[current_combolist]>0)
11298 {
11299 First[current_combolist]-=zc_min(First[current_combolist],combolist[j].w*z);
11300 }
11301 }
11302 goto domouse_donez;
11303 }
11304 }
11305 }
11306
11307 z=abs(mouse_z);
11308
11309 if(real_mini.rect(x,y))
11310 {
11311 for(int32_t i=0; i<z; ++i)
11312 {
11313 if(mouse_z>0) onIncMap();
11314 else onDecMap();
11315 }
11316 goto domouse_donez;
11317 }
11318
11319 if(is_compact && compact_square_panels
11320 && squares_panel.rect(x,y))
11321 {
11322 cycle_compact_sqr(mouse_z < 0);
11323 goto domouse_donez;
11324 }
11325 domouse_donez:
11326 position_mouse_z(0);
11327 }
11328
11329 // Mouse buttons.
11330 {
11331 ALLEGRO_MOUSE_STATE state;
11332 al_get_mouse_state(&state);
11333
11334 static bool btn_4_was_down;
11335 static bool btn_5_was_down;
11336
11337 bool btn_4_down = al_mouse_button_down(&state, 4);
11338 bool btn_5_down = al_mouse_button_down(&state, 5);
11339
11340 if (btn_4_was_down && !btn_4_down)
11341 Map.GoBack();
11342 else if (btn_5_was_down && !btn_5_down)
11343 Map.GoForward();
11344
11345 btn_4_was_down = btn_4_down;
11346 btn_5_was_down = btn_5_down;
11347 }
11348
11349 font = tfont;
11350 active_visible_screen = nullptr;
11351 }
11352
11353 int32_t d_viewpal_proc(int32_t msg, DIALOG *d, int32_t c)
11354 {
11355 int32_t ret = d_bitmap_proc(msg, d, c);
11356 char* buf = (char*)d->dp2; //buffer to store the color code in
11357 DIALOG* d2 = (DIALOG*)d->dp3; //DIALOG* to update the text proc
11358 if(!buf)
11359 return ret;
11360 switch(msg)
11361 {
11362 case MSG_IDLE:
11363 case MSG_GOTMOUSE:
11364 case MSG_LOSTMOUSE:
11365 break;
11366 default:
11367 return ret;
11368 }
11369 char t[16];
11370 memcpy(t, buf, 16);
11371 int32_t x = gui_mouse_x() - d->x;
11372 int32_t y = gui_mouse_y() - d->y;
11373 if(msg != MSG_LOSTMOUSE && isinRect(x, y, 0, 0, d->w-1, d->h-1))
11374 {
11375 float palscale = 1.5;
11376 for(int32_t i = 0; i<256; ++i)
11377 if(isinRect(x,y,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale)))
11378 {
11379 sprintf(buf, "0x%02X (%03d) ", i, i); //Extra spaces to increase drawn width, so it draws the blank area
11380 break;
11381 }
11382 }
11383 else memset(buf, ' ', 15);
11384 if(strcmp(buf, t) && d2 && d2->proc == jwin_text_proc && d2->dp == d->dp2)
11385 object_message(d2, MSG_DRAW, 0);
11386 return ret;
11387 }
11388
11389 static DIALOG showpal_dlg[] =
11390 {
11391 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11392 { jwin_win_proc, 24, 68, 272, 119, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Palette", NULL, NULL },
11393 { jwin_frame_proc, 30, 76+16, 260, 68, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11394 { d_viewpal_proc, 32, 76+18, 256, 64, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11395 { jwin_text_proc, 32+8,76+18+66, 20, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
11396 { jwin_button_proc, 130, 144+18, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11397 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11398 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11399 };
11400
11401 int32_t onShowPal()
11402 {
11403 float palscale = 1.5;
11404
11405 BITMAP *palbmp = create_bitmap_ex(8,(int32_t)(256*palscale),(int32_t)(64*palscale));
11406
11407 if(!palbmp)
11408 return D_O_K;
11409 clear_to_color(palbmp,jwin_pal[jcBOX]); //If not cleared, random static appears between swatches! -E
11410 showpal_dlg[0].dp2=get_zc_font(font_lfont);
11411
11412 for(int32_t i=0; i<256; i++)
11413 rectfill(palbmp,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale),i);
11414 showpal_dlg[2].dp=(void *)palbmp;
11415 char buf[16] = {0};
11416 showpal_dlg[2].dp2=(void *)buf;
11417 showpal_dlg[2].dp3=(void *)&(showpal_dlg[3]);
11418 showpal_dlg[3].dp=(void *)buf;
11419 showpal_dlg[3].dp2=(void *)get_zc_font(font_deffont);
11420
11421 large_dialog(showpal_dlg);
11422 do_zqdialog(showpal_dlg,2);
11423 destroy_bitmap(palbmp);
11424 return D_O_K;
11425 }
11426
11427 static DIALOG csetfix_dlg[] =
11428 {
11429 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11430 { jwin_win_proc, 72, 80, 176+1, 96+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "CSet Fix", NULL, NULL },
11431 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11432 { jwin_radio_proc, 104+22, 108, 80+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full Screen", NULL, NULL },
11433 { jwin_radio_proc, 104+22, 118+2, 80+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Dungeon Floor", NULL, NULL },
11434 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
11435 { jwin_check_proc, 104+22, 128+4, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, (void *) "All Layers", NULL, NULL },
11436 { jwin_button_proc, 90, 152, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11437 { jwin_button_proc, 170, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11438 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11439 };
11440
11441 int32_t onCSetFix()
11442 {
11443 restore_mouse();
11444 csetfix_dlg[0].dp2=get_zc_font(font_lfont);
11445 int32_t s=2,x2=14,y2=9;
11446
11447 large_dialog(csetfix_dlg);
11448
11449 if(do_zqdialog(csetfix_dlg,-1)==6)
11450 {
11451 if(csetfix_dlg[2].flags&D_SELECTED)
11452 {
11453 s=0;
11454 x2=16;
11455 y2=11;
11456 }
11457
11458 if(csetfix_dlg[5].flags&D_SELECTED)
11459 {
11460 /*
11461 int32_t drawmap, drawscr;
11462 if (CurrentLayer==0)
11463 {
11464 drawmap=Map.getCurrMap();
11465 drawscr=Map.getCurrScr();
11466 }
11467 else
11468 {
11469 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
11470 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
11471 }
11472 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
11473 if(!draw_mapscr) return;
11474 mark_save_dirty();
11475 Map.Ugo();
11476
11477 if(!(draw_mapscr->valid&mVALID))
11478 {
11479 Map.CurrScr()->valid|=mVALID;
11480 draw_mapscr->valid|=mVALID;
11481 Map.setcolor(Color);
11482 }
11483 for(int32_t i=0; i<176; i++)
11484 {
11485 draw_mapscr->data[i]=Combo;
11486 draw_mapscr->cset[i]=CSet;
11487 }
11488 refresh(rMAP+rSCRMAP);
11489 */
11490 }
11491
11492 Map.StartListCommand();
11493 for(int32_t y=s; y<y2; y++)
11494 {
11495 for(int32_t x=s; x<x2; x++)
11496 {
11497 Map.DoSetComboCommand(Map.getCurrMap(), Map.getCurrScr(), (y<<4)+x, -1, CSet);
11498 }
11499 }
11500 Map.FinishListCommand();
11501
11502 refresh(rMAP);
11503 mark_save_dirty();
11504 }
11505
11506 return D_O_K;
11507 }
11508 static bool doAllSolidWater()
11509 {
11510 for(int32_t i=0; i < MAXCOMBOS; ++i)
11511 {
11512 if(combo_class_buf[combobuf[i].type].water!=0)
11513 {
11514 combobuf[i].walk |= 0x0F; //Solid
11515 }
11516 }
11517 return true;
11518 }
11519 static bool doNoSolidWater()
11520 {
11521 for(int32_t i=0; i < MAXCOMBOS; ++i)
11522 {
11523 if(combo_class_buf[combobuf[i].type].water!=0)
11524 {
11525 combobuf[i].walk &= ~0x0F; //Non-solid
11526 }
11527 }
11528 return true;
11529 }
11530 int32_t onWaterSolidity()
11531 {
11532 AlertFuncDialog("Water Conversion",
11533 "Forcibly set the solidity of all 'Liquid' combos in the quest?",
11534 ""
11535 ).add_buttons(2,
11536 { "Solid", "Non-Solid", "Cancel" },
11537 { doAllSolidWater, doNoSolidWater, nullptr }
11538 ).show();
11539 return D_O_K;
11540 }
11541
11542 static bool doAllEffectSquare()
11543 {
11544 for(int32_t i=0; i < MAXCOMBOS; ++i)
11545 {
11546 combobuf[i].walk |= 0xF0; //Effect
11547 }
11548 return true;
11549 }
11550 static bool doBlankEffectSquare()
11551 {
11552 for(int32_t i=0; i < MAXCOMBOS; ++i)
11553 {
11554 if(combobuf[i].is_blank(true))
11555 {
11556 combobuf[i].walk |= 0xF0; //Effect
11557 }
11558 }
11559 return true;
11560 }
11561
11562 int32_t onEffectFix()
11563 {
11564 AlertFuncDialog("Effect Square Conversion",
11565 "Forcibly fill the green effect square of all combos in the quest?",
11566 ""
11567 ).add_buttons(2,
11568 { "All", "Blank Only", "Cancel" },
11569 { doAllEffectSquare, doBlankEffectSquare, nullptr }
11570 ).show();
11571 return D_O_K;
11572 }
11573
11574 static bool clear_green_arrival_squares()
11575 {
11576 for(mapscr& scr : TheMaps)
11577 {
11578 if(!scr.valid) continue;
11579 scr.warparrivalx = 0;
11580 scr.warparrivaly = 0;
11581 }
11582 set_qr(qr_NOARRIVALPOINT, true);
11583 return true;
11584 }
11585
11586 static bool replace_green_arrival_squares()
11587 {
11588 // Check for conflicts first
11589 bool has_conflicts = false;
11590
11591 for(mapscr& scr : TheMaps)
11592 {
11593 if(!scr.valid) continue;
11594 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11595 if(scr.warpreturnx[0] || scr.warpreturny[0])
11596 {
11597 has_conflicts = true;
11598 break;
11599 }
11600 }
11601
11602 enum
11603 {
11604 NOT_ASKED = -1,
11605 MODE_FORCE, MODE_IGNORE, MODE_FIND_IGNORE, MODE_FIND_FORCE, MODE_CANCEL
11606 };
11607 int mode = NOT_ASKED;
11608
11609 if(has_conflicts)
11610 {
11611 AlertFuncDialog("Handle Conflicts",
11612 "Warp Square A is not available for all screens that have arrival squares."
11613 " How should this be handled? (See '?' for more info)",
11614 "Overwrite A: Replace the existing warp return square A with the position of the green arrival square"
11615 "\nIgnore: Do nothing if warp return square A exists"
11616 "\nFind Space or Ignore: Choose another, unused, square to set to the position of the green arrival square."
11617 " If none are unused, 'Ignore' instead."
11618 "\nFind Space or Overwrite: Choose another, unused square to set to the position of the green arrival square."
11619 " If none are unused, 'Overwrite A' instead."
11620 "\nCancel: Don't do anything"
11621 ).add_buttons(1,
11622 { "Overwrite A", "Ignore", "Find Space or Ignore", "Find Space or Overwrite A", "Cancel" },
11623 mode
11624 ).show();
11625 if(mode == NOT_ASKED || mode == MODE_CANCEL)
11626 return false;
11627 }
11628 for(mapscr& scr : TheMaps)
11629 {
11630 if(!scr.valid) continue;
11631 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11632 int indx = 0;
11633 if(scr.warpreturnx[0] || scr.warpreturny[0])
11634 {
11635 if(mode == MODE_IGNORE) continue; // Warp A not free, so ignore
11636 if(mode != MODE_FORCE)
11637 {
11638 for(int q = 1; q < 4; ++q)
11639 {
11640 if(scr.warpreturnx[q] || scr.warpreturny[q])
11641 continue;
11642 indx = q; // Use this warp, since it's free
11643 break;
11644 }
11645 if(indx == 0 && mode == MODE_FIND_IGNORE)
11646 continue; // Nothing free, so ignore
11647 }
11648 }
11649 scr.warpreturnx[indx] = scr.warparrivalx;
11650 scr.warpreturny[indx] = scr.warparrivaly;
11651 scr.warparrivalx = 0;
11652 scr.warparrivaly = 0;
11653 }
11654 set_qr(qr_NOARRIVALPOINT, true);
11655 return true;
11656 }
11657
11658 int32_t onRemoveOldArrivalSquare()
11659 {
11660 AlertFuncDialog("Arrival Square Removal",
11661 "Clear the old green 'Arrival' squares for the whole quest?"
11662 "\n(There will be no further confirmation, and this operation cannot be undone)",
11663 ""
11664 ).add_buttons(2,
11665 { "Replace With Blue Return Square", "Clear Completely", "Cancel" },
11666 { replace_green_arrival_squares, clear_green_arrival_squares, nullptr }
11667 ).show();
11668 return D_O_K;
11669 }
11670
11671 byte* getPalPointer(int32_t pal, int32_t cset)
11672 {
11673 if (pal < 0) return colordata + CSET(cset)*3;
11674 byte* ret = colordata + CSET(pal*pdLEVEL+poLEVEL)*3;
11675 switch(cset)
11676 {
11677 case 2: case 3: case 4:
11678 return ret + CSET(cset-2)*3;
11679 case 9:
11680 return ret + CSET(3)*3;
11681 case 1:
11682 return ret + CSET(13)*3;
11683 case 5:
11684 return ret + CSET(14)*3;
11685 case 7:
11686 return ret + CSET(15)*3;
11687 case 8:
11688 return ret + CSET(16)*3;
11689 }
11690 return NULL;
11691 }
11692
11693 void copyCSet(int32_t destpal, int32_t destcset, int32_t srcpal, int32_t srccset)
11694 {
11695 byte* dest = getPalPointer(destpal, destcset);
11696 byte* src = getPalPointer(srcpal, srccset);
11697 if (dest && src)
11698 {
11699 memcpy(dest, src, 16*3);
11700 }
11701 }
11702
11703 void setColorPalette(int32_t flags, int32_t lowpal, int32_t highpal)
11704 {
11705 for (auto q = lowpal; q <= highpal; ++q)
11706 {
11707 for (auto c = 0; c < 12; ++c)
11708 {
11709 if (!(flags&(1<<c))) continue;
11710 copyCSet(q, c, -1, c);
11711 }
11712 }
11713 }
11714
11715 void setPitDamage(int32_t flags, int32_t lowcombo, int32_t highcombo, int32_t damage)
11716 {
11717 for(int32_t i=lowcombo; i < highcombo; ++i)
11718 {
11719 if((combobuf[i].type == cPITFALL && (flags & (1<<0)))
11720 || (combobuf[i].type == cWATER && !(combobuf[i].usrflags & (1<<0)) && (flags & (1<<1)))
11721 || (combobuf[i].type == cWATER && (combobuf[i].usrflags & (1<<0)) && (flags & (1<<2))))
11722 {
11723 if ((combobuf[i].type != cPITFALL || (flags & (1<<9)) || !(combobuf[i].usrflags & (1<<0)))
11724 && ((flags & (1<<8)) || combobuf[i].attributes[0] == 0))
11725 combobuf[i].attributes[0] = damage*10000;
11726 }
11727 }
11728 }
11729
11730 static DIALOG template_dlg[] =
11731 {
11732 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11733 { jwin_win_proc, 72, 80, 176+1, 116+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "NES Dungeon Template", NULL, NULL },
11734 { d_comboframe_proc, 178, 122+3, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11735 { d_combo_proc, 180, 124+3, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11736 // { d_bitmap_proc, 180, 104, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11737 { jwin_radio_proc, 104+33, 128+3, 64+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Floor:", NULL, NULL },
11738 { jwin_radio_proc, 104+33, 148+3, 64+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "No Floor", NULL, NULL },
11739 { jwin_button_proc, 90, 172, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11740 { jwin_button_proc, 170, 172, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11741 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11742 { jwin_text_proc, 104, 102, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "This copies the contents of", NULL, NULL },
11743 { jwin_text_proc, 104, 112, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "screen 83 of the current map.", NULL, NULL },
11744 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11745 };
11746
11747 int32_t onTemplate()
11748 {
11749 static bool donethis=false;
11750
11751 if(!donethis||!(key[KEY_LSHIFT]||key[KEY_RSHIFT]))
11752 {
11753 template_dlg[2].d1=Combo;
11754 template_dlg[2].fg=CSet;
11755 donethis=true;
11756 }
11757
11758 restore_mouse();
11759
11760 if(Map.getCurrScr()==TEMPLATE)
11761 return D_O_K;
11762
11763 // BITMAP *floor_bmp = create_bitmap_ex(8,16,16);
11764 // if(!floor_bmp) return D_O_K;
11765 template_dlg[0].dp2=get_zc_font(font_lfont);
11766 // put_combo(floor_bmp,0,0,Combo,CSet,0,0);
11767 // template_dlg[2].dp=floor_bmp;
11768
11769 large_dialog(template_dlg);
11770
11771 if(do_zqdialog(template_dlg,-1)==5)
11772 {
11773 mark_save_dirty();
11774 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
11775 Map.DoTemplateCommand((template_dlg[3].flags==D_SELECTED) ? template_dlg[2].d1 : -1, template_dlg[2].fg, screen);
11776 refresh(rMAP+rSCRMAP);
11777 }
11778
11779 // destroy_bitmap(floor_bmp);
11780 return D_O_K;
11781 }
11782
11783 static DIALOG cflag_dlg[] =
11784 {
11785 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
11786 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11787 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11788 12 { jwin_abclist_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11789 12 { jwin_button_proc, 70, 163, 51, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11790 12 { jwin_button_proc, 190, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11791 12 { jwin_button_proc, 130, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Help", NULL, NULL },
11792 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11793 };
11794
11795
11796 void questrev_help()
11797 {
11798 displayinfo("Help","The revision number of your quest.");
11799 }
11800
11801 void questminrev_help()
11802 {
11803 displayinfo("Help","If a player's saved game was from a revision less than the minimum revision, they have to restart from the beginning. This is useful if you make major changes to your quest.");
11804 }
11805
11806 int32_t select_cflag(const char *prompt,int32_t flag)
11807 {
11808 cflag_dlg[0].dp=(void *)prompt;
11809 cflag_dlg[0].dp2=get_zc_font(font_lfont);
11810 GUI::ListData ld = GUI::ZCListData::mapflag(numericalFlags, true);
11811 ListData select_cflag_list = ld.getJWin(&font);
11812 auto index = ld.findIndex(flag);
11813 cflag_dlg[2].d1=index.value_or(0);
11814 cflag_dlg[2].dp=(void *) &select_cflag_list;
11815
11816 large_dialog(cflag_dlg);
11817
11818 int32_t ret;
11819
11820 do
11821 {
11822 ret=do_zqdialog(cflag_dlg,2);
11823
11824 if(ret==5)
11825 {
11826 cflag_help(ld.getValue(cflag_dlg[2].d1));
11827 }
11828 }
11829 while(ret==5);
11830
11831 if(ret==0||ret==4)
11832 {
11833 position_mouse_z(0);
11834 return -1;
11835 }
11836
11837 return ld.getValue(cflag_dlg[2].d1);
11838 }
11839
11840 int32_t select_flag(int32_t &f)
11841 {
11842 int32_t ret=select_cflag("Flag Type",f);
11843
11844 if(ret>=0)
11845 {
11846 f=ret;
11847 return true;
11848 }
11849
11850 return false;
11851 }
11852
11853 int32_t d_scombo_proc(int32_t msg,DIALOG *d,int32_t c)
11854 {
11855 //these are here to bypass compiler warnings about unused arguments
11856 c=c;
11857
11858 switch(msg)
11859 {
11860 case MSG_CLICK:
11861 {
11862 int32_t c2=d->d1;
11863 int32_t cs=d->fg;
11864 int32_t f=d->d2;
11865
11866 if(d->bg==1 || (CHECK_CTRL_CMD))
11867 {
11868 while(gui_mouse_b())
11869 {
11870 /* do nothing */
11871 rest(1);
11872 }
11873
11874 if(select_flag(f))
11875 {
11876 d->d2=f;
11877
11878 }
11879 }
11880 else if(key[KEY_LSHIFT])
11881 {
11882 if(gui_mouse_b()&1)
11883 {
11884 d->d1++;
11885
11886 if(d->d1>=MAXCOMBOS) d->d1=0;
11887 }
11888 else if(gui_mouse_b()&2)
11889 {
11890 d->d1--;
11891
11892 if(d->d1<0) d->d1=MAXCOMBOS-1;
11893 }
11894 }
11895 else if(key[KEY_RSHIFT])
11896 {
11897 if(gui_mouse_b()&1)
11898 {
11899 d->fg++;
11900
11901 if(d->fg>11) d->fg=0;
11902 }
11903 else if(gui_mouse_b()&2)
11904 {
11905 d->fg--;
11906
11907 if(d->fg<0) d->fg=11;
11908 }
11909 }
11910 else if(key[KEY_ALT])
11911 {
11912 if(gui_mouse_b()&1)
11913 {
11914 d->d1 = Combo;
11915 d->fg = CSet;
11916 }
11917 }
11918 else
11919 {
11920 if(select_combo_2(c2, cs))
11921 {
11922 d->d1=c2;
11923 d->fg=cs;
11924 }
11925 }
11926
11927 return D_REDRAW;
11928 }
11929 break;
11930
11931 case MSG_DRAW:
11932 d->w = 32;
11933 d->h = 32;
11934
11935 BITMAP *buf = create_bitmap_ex(8,16,16);
11936 BITMAP *bigbmp = create_bitmap_ex(8,d->w,d->h);
11937
11938 if(buf && bigbmp)
11939 {
11940 clear_bitmap(buf);
11941
11942 if(d->bg) //flags only
11943 {
11944 put_flag(buf,0,0,d->d2);
11945 }
11946 else if(d->d1)
11947 {
11948 putcombo(buf,0,0,d->d1,d->fg);
11949
11950 if(Flags&cFLAGS)
11951 put_flags(buf,0,0,d->d1,d->fg,cFLAGS,d->d2);
11952 }
11953
11954 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, d->w, d->h);
11955 destroy_bitmap(buf);
11956 blit(bigbmp,screen,0,0,d->x-1,d->y-1,d->w,d->h);
11957 destroy_bitmap(bigbmp);
11958 }
11959
11960
11961 /*BITMAP *buf = create_bitmap_ex(8,16,16);
11962 if(buf)
11963 {
11964 clear_bitmap(buf);
11965 if(d->d1)
11966 putcombo(buf,0,0,d->d1,d->fg);
11967
11968 blit(buf,screen,0,0,d->x,d->y,d->w,d->h);
11969 destroy_bitmap(buf);
11970 }*/
11971 break;
11972 }
11973
11974 return D_O_K;
11975 }
11976
11977 int32_t onSecretF();
11978
11979 static int32_t secret_burn_list[] =
11980 {
11981 // dialog control number
11982 4, 5, 6, 7, 48, 49, 50, 51, 92, 93, 94, 95, -1
11983 };
11984
11985 static int32_t secret_arrow_list[] =
11986 {
11987 // dialog control number
11988 8, 9, 10, 52, 53, 54, 96, 97, 98, -1
11989 };
11990
11991 static int32_t secret_bomb_list[] =
11992 {
11993 // dialog control number
11994 11, 12, 55, 56, 99, 100, -1
11995 };
11996
11997 static int32_t secret_boomerang_list[] =
11998 {
11999 // dialog control number
12000 13, 14, 15, 57, 58, 59, 101, 102, 103, -1
12001 };
12002
12003 static int32_t secret_magic_list[] =
12004 {
12005 // dialog control number
12006 16, 17, 60, 61, 104, 105, -1
12007 };
12008
12009 static int32_t secret_sword_list[] =
12010 {
12011 // dialog control number
12012 18, 19, 20, 21, 22, 23, 24, 25, 62, 63, 64, 65, 66, 67, 68, 69, 106, 107, 108, 109, 110, 111, 112, 113, -1
12013 };
12014
12015 static int32_t secret_misc_list[] =
12016 {
12017 // dialog control number
12018 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, -1
12019 };
12020
12021 static TABPANEL secret_tabs[] =
12022 {
12023 // (text)
12024 { (char *)"Burn", D_SELECTED, secret_burn_list, 0, NULL },
12025 { (char *)"Arrow", 0, secret_arrow_list, 0, NULL },
12026 { (char *)"Bomb", 0, secret_bomb_list, 0, NULL },
12027 { (char *)"Boomerang", 0, secret_boomerang_list, 0, NULL },
12028 { (char *)"Magic", 0, secret_magic_list, 0, NULL },
12029 { (char *)"Sword", 0, secret_sword_list, 0, NULL },
12030 { (char *)"Misc", 0, secret_misc_list, 0, NULL },
12031 { NULL, 0, NULL, 0, NULL }
12032 };
12033
12034 static DIALOG secret_dlg[] =
12035 {
12036 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
12037 { jwin_win_proc, 0, 0, 301, 212, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12038 { jwin_tab_proc, 6, 25, 289, 156, 0, 0, 0, 0, 0, 0, (void *) secret_tabs, NULL, (void *)secret_dlg },
12039 { jwin_button_proc, 80, 187, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
12040 { jwin_button_proc, 160, 187, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
12041 // 4
12042 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Fire", NULL, NULL },
12043 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Strong Fire", NULL, NULL },
12044 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Fire", NULL, NULL },
12045 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Divine Fire", NULL, NULL },
12046 //8
12047 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Arrow", NULL, NULL },
12048 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Silver Arrow", NULL, NULL },
12049 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Golden Arrow", NULL, NULL },
12050 //11
12051 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Bomb", NULL, NULL },
12052 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Super Bomb", NULL, NULL },
12053 //13
12054 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Boomerang", NULL, NULL },
12055 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Boomerang", NULL, NULL },
12056 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Fire Boomerang", NULL, NULL },
12057 //16
12058 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand Magic", NULL, NULL },
12059 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Magic", NULL, NULL },
12060 //18
12061 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword", NULL, NULL },
12062 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword", NULL, NULL },
12063 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword", NULL, NULL },
12064 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword", NULL, NULL },
12065 { jwin_text_proc, 160, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword Beam", NULL, NULL },
12066 { jwin_text_proc, 160, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword Beam", NULL, NULL },
12067 { jwin_text_proc, 160, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword Beam", NULL, NULL },
12068 { jwin_text_proc, 160, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword Beam", NULL, NULL },
12069 //26
12070 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Stairs", NULL, NULL },
12071 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Fireball", NULL, NULL },
12072 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hookshot", NULL, NULL },
12073 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand", NULL, NULL },
12074 { jwin_text_proc, 12, 141, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hammer", NULL, NULL },
12075 { jwin_text_proc, 12, 163, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Weapon", NULL, NULL },
12076 //32
12077 { jwin_ctext_proc, 235, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Flags 16-31", NULL, NULL },
12078 { jwin_text_proc, 87, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Secrets->Next (Flag only)", NULL, NULL },
12079 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 03", NULL, NULL },
12080 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 04", NULL, NULL },
12081 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 05", NULL, NULL },
12082 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 06", NULL, NULL },
12083 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 07", NULL, NULL },
12084 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 08", NULL, NULL },
12085 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 09", NULL, NULL },
12086 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 10", NULL, NULL },
12087 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 11", NULL, NULL },
12088 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 12", NULL, NULL },
12089 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 13", NULL, NULL },
12090 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 14", NULL, NULL },
12091 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 15", NULL, NULL },
12092 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 16", NULL, NULL },
12093 //48 (burn)
12094 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12095 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12096 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12097 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12098 //52 (arrow)
12099 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12100 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12101 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12102 //55 (bomb)
12103 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12104 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12105 //57 (boomerang)
12106 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12107 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12108 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12109 //60 (magic)
12110 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12111 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12112 //62 (sword)
12113 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12114 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12115 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12116 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12117 { jwin_frame_proc, 256, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12118 { jwin_frame_proc, 256, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12119 { jwin_frame_proc, 256, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12120 { jwin_frame_proc, 256, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12121 //70 (misc)
12122 { jwin_frame_proc, 63, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12123 { jwin_frame_proc, 63, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12124 { jwin_frame_proc, 63, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12125 { jwin_frame_proc, 63, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12126 { jwin_frame_proc, 63, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12127 { jwin_frame_proc, 63, 157, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12128 //76 (16-32)
12129 { jwin_frame_proc, 192, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12130 { jwin_frame_proc, 214, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12131 { jwin_frame_proc, 236, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12132 { jwin_frame_proc, 258, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12133 { jwin_frame_proc, 192, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12134 { jwin_frame_proc, 214, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12135 { jwin_frame_proc, 236, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12136 { jwin_frame_proc, 258, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12137 { jwin_frame_proc, 192, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12138 { jwin_frame_proc, 214, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12139 { jwin_frame_proc, 236, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12140 { jwin_frame_proc, 258, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12141 { jwin_frame_proc, 192, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12142 { jwin_frame_proc, 214, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12143 { jwin_frame_proc, 236, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12144 { jwin_frame_proc, 258, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12145
12146 //92 (burn)
12147 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12148 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12149 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12150 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12151 //96 (arrow)
12152 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12153 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12154 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12155 //99 (bomb)
12156 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12157 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12158 //101 (boomerang)
12159 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12160 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12161 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12162 //104 (magic)
12163 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12164 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12165 //106 (sword)
12166 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12167 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12168 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12169 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12170 { d_scombo_proc, 258, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12171 { d_scombo_proc, 258, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12172 { d_scombo_proc, 258, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12173 { d_scombo_proc, 258, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12174 //114 (misc)
12175 { d_scombo_proc, 65, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12176 { d_scombo_proc, 65, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12177 { d_scombo_proc, 65, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12178 { d_scombo_proc, 65, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12179 { d_scombo_proc, 65, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12180 { d_scombo_proc, 65, 159, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12181 //120 (16-32)
12182 { d_scombo_proc, 194, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12183 { d_scombo_proc, 216, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12184 { d_scombo_proc, 238, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12185 { d_scombo_proc, 260, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12186 { d_scombo_proc, 194, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12187 { d_scombo_proc, 216, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12188 { d_scombo_proc, 238, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12189 { d_scombo_proc, 260, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12190 { d_scombo_proc, 194, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12191 { d_scombo_proc, 216, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12192 { d_scombo_proc, 238, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12193 { d_scombo_proc, 260, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12194 { d_scombo_proc, 194, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12195 { d_scombo_proc, 216, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12196 { d_scombo_proc, 238, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12197 { d_scombo_proc, 260, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12198 //136 Secrets->Next
12199 { jwin_frame_proc, 158, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12200 { d_scombo_proc, 160, 49, 16, 16, 0, 1, 0, 0, 0, 0, NULL, NULL, NULL },
12201 //138
12202 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
12203 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 'f', 0, 0, 0, (void *) onSecretF, NULL, NULL },
12204 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12205 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12206 };
12207
12208 int32_t onSecretF()
12209 {
12210 Flags^=cFLAGS;
12211 object_message(secret_dlg+1, MSG_DRAW, 0);
12212 return D_O_K;
12213 }
12214
12215
12216 int32_t onSecretCombo()
12217 {
12218 secret_dlg[0].dp2=get_zc_font(font_lfont);
12219
12220
12221 mapscr *s;
12222
12223 if(CurrentLayer==0)
12224 {
12225 s=Map.CurrScr();
12226 }
12227 else
12228 {
12229 // s=TheMaps[(Map.CurrScr()->layermap[CurrentLayer-1]-1)*MAPSCRS+(Map.CurrScr()->layerscreen[CurrentLayer-1])];
12230 s=Map.AbsoluteScr((Map.CurrScr()->layermap[CurrentLayer-1]-1), (Map.CurrScr()->layerscreen[CurrentLayer-1]));
12231 }
12232 if(!s) return D_O_K;
12233
12234 char secretcombonumstr[27];
12235 sprintf(secretcombonumstr,"Secret Combos for Layer %d", CurrentLayer);
12236 secret_dlg[0].dp = secretcombonumstr;
12237
12238 secret_dlg[92].d1 = s->secretcombo[sBCANDLE];
12239 secret_dlg[92].fg = s->secretcset[sBCANDLE];
12240 secret_dlg[92].d2 = s->secretflag[sBCANDLE];
12241
12242 secret_dlg[93].d1 = s->secretcombo[sRCANDLE];
12243 secret_dlg[93].fg = s->secretcset[sRCANDLE];
12244 secret_dlg[93].d2 = s->secretflag[sRCANDLE];
12245
12246 secret_dlg[94].d1 = s->secretcombo[sWANDFIRE];
12247 secret_dlg[94].fg = s->secretcset[sWANDFIRE];
12248 secret_dlg[94].d2 = s->secretflag[sWANDFIRE];
12249
12250 secret_dlg[95].d1 = s->secretcombo[sDIVINEFIRE];
12251 secret_dlg[95].fg = s->secretcset[sDIVINEFIRE];
12252 secret_dlg[95].d2 = s->secretflag[sDIVINEFIRE];
12253
12254 secret_dlg[96].d1 = s->secretcombo[sARROW];
12255 secret_dlg[96].fg = s->secretcset[sARROW];
12256 secret_dlg[96].d2 = s->secretflag[sARROW];
12257
12258 secret_dlg[97].d1 = s->secretcombo[sSARROW];
12259 secret_dlg[97].fg = s->secretcset[sSARROW];
12260 secret_dlg[97].d2 = s->secretflag[sSARROW];
12261
12262 secret_dlg[98].d1 = s->secretcombo[sGARROW];
12263 secret_dlg[98].fg = s->secretcset[sGARROW];
12264 secret_dlg[98].d2 = s->secretflag[sGARROW];
12265
12266 secret_dlg[99].d1 = s->secretcombo[sBOMB];
12267 secret_dlg[99].fg = s->secretcset[sBOMB];
12268 secret_dlg[99].d2 = s->secretflag[sBOMB];
12269
12270 secret_dlg[100].d1 = s->secretcombo[sSBOMB];
12271 secret_dlg[100].fg = s->secretcset[sSBOMB];
12272 secret_dlg[100].d2 = s->secretflag[sSBOMB];
12273
12274 for(int32_t i=0; i<3; i++)
12275 {
12276 secret_dlg[101+i].d1 = s->secretcombo[sBRANG+i];
12277 secret_dlg[101+i].fg = s->secretcset[sBRANG+i];
12278 secret_dlg[101+i].d2 = s->secretflag[sBRANG+i];
12279 }
12280
12281 for(int32_t i=0; i<2; i++)
12282 {
12283 secret_dlg[104+i].d1 = s->secretcombo[sWANDMAGIC+i];
12284 secret_dlg[104+i].fg = s->secretcset[sWANDMAGIC+i];
12285 secret_dlg[104+i].d2 = s->secretflag[sWANDMAGIC+i];
12286 }
12287
12288 for(int32_t i=0; i<8; i++)
12289 {
12290 secret_dlg[106+i].d1 = s->secretcombo[sSWORD+i];
12291 secret_dlg[106+i].fg = s->secretcset[sSWORD+i];
12292 secret_dlg[106+i].d2 = s->secretflag[sSWORD+i];
12293 }
12294
12295 secret_dlg[114].d1 = s->secretcombo[sSTAIRS];
12296 secret_dlg[114].fg = s->secretcset[sSTAIRS];
12297 secret_dlg[114].d2 = s->secretflag[sSTAIRS];
12298
12299 secret_dlg[115].d1 = s->secretcombo[sREFFIREBALL];
12300 secret_dlg[115].fg = s->secretcset[sREFFIREBALL];
12301 secret_dlg[115].d2 = s->secretflag[sREFFIREBALL];
12302
12303 for(int32_t i=0; i<4; i++)
12304 {
12305 secret_dlg[116+i].d1 = s->secretcombo[sHOOKSHOT+i];
12306 secret_dlg[116+i].fg = s->secretcset[sHOOKSHOT+i];
12307 secret_dlg[116+i].d2 = s->secretflag[sHOOKSHOT+i];
12308 }
12309
12310 for(int32_t i=0; i<16; i++)
12311 {
12312 secret_dlg[120+i].d1 = s->secretcombo[sSECRET01+i];
12313 secret_dlg[120+i].fg = s->secretcset[sSECRET01+i];
12314 secret_dlg[120+i].d2 = s->secretflag[sSECRET01+i];
12315 }
12316
12317 //Sec->Next doesn't have a combo/cset value associated
12318 secret_dlg[137].d1 = 0;
12319 secret_dlg[137].fg = 0;
12320 secret_dlg[137].d2 = s->secretflag[sSECNEXT];
12321
12322 large_dialog(secret_dlg,1.75);
12323
12324 for(int32_t q = 0; secret_dlg[q].proc != NULL; ++q)
12325 {
12326 if(secret_dlg[q].proc == jwin_frame_proc)
12327 secret_dlg[q].w = secret_dlg[q].h = 36;
12328 }
12329
12330 if(do_zqdialog(secret_dlg,3) == 2)
12331 {
12332 mark_save_dirty();
12333 s->secretcombo[sBCANDLE] = secret_dlg[92].d1;
12334 s->secretcset[sBCANDLE] = secret_dlg[92].fg;
12335 s->secretflag[sBCANDLE] = secret_dlg[92].d2;
12336
12337 s->secretcombo[sRCANDLE] = secret_dlg[93].d1;
12338 s->secretcset[sRCANDLE] = secret_dlg[93].fg;
12339 s->secretflag[sRCANDLE] = secret_dlg[93].d2;
12340
12341 s->secretcombo[sWANDFIRE] = secret_dlg[94].d1;
12342 s->secretcset[sWANDFIRE] = secret_dlg[94].fg;
12343 s->secretflag[sWANDFIRE] = secret_dlg[94].d2;
12344
12345 s->secretcombo[sDIVINEFIRE] = secret_dlg[95].d1;
12346 s->secretcset[sDIVINEFIRE] = secret_dlg[95].fg;
12347 s->secretflag[sDIVINEFIRE] = secret_dlg[95].d2;
12348
12349 s->secretcombo[sARROW] = secret_dlg[96].d1;
12350 s->secretcset[sARROW] = secret_dlg[96].fg;
12351 s->secretflag[sARROW] = secret_dlg[96].d2;
12352
12353 s->secretcombo[sSARROW] = secret_dlg[97].d1;
12354 s->secretcset[sSARROW] = secret_dlg[97].fg;
12355 s->secretflag[sSARROW] = secret_dlg[97].d2;
12356
12357 s->secretcombo[sGARROW] = secret_dlg[98].d1;
12358 s->secretcset[sGARROW] = secret_dlg[98].fg;
12359 s->secretflag[sGARROW] = secret_dlg[98].d2;
12360
12361 s->secretcombo[sBOMB] = secret_dlg[99].d1;
12362 s->secretcset[sBOMB] = secret_dlg[99].fg;
12363 s->secretflag[sBOMB] = secret_dlg[99].d2;
12364
12365 s->secretcombo[sSBOMB] = secret_dlg[100].d1;
12366 s->secretcset[sSBOMB] = secret_dlg[100].fg;
12367 s->secretflag[sSBOMB] = secret_dlg[100].d2;
12368
12369 for(int32_t i=0; i<3; i++)
12370 {
12371 s->secretcombo[sBRANG+i] = secret_dlg[101+i].d1;
12372 s->secretcset[sBRANG+i] = secret_dlg[101+i].fg;
12373 s->secretflag[sBRANG+i] = secret_dlg[101+i].d2;
12374 }
12375
12376 for(int32_t i=0; i<2; i++)
12377 {
12378 s->secretcombo[sWANDMAGIC+i] = secret_dlg[104+i].d1;
12379 s->secretcset[sWANDMAGIC+i] = secret_dlg[104+i].fg;
12380 s->secretflag[sWANDMAGIC+i] = secret_dlg[104+i].d2;
12381 }
12382
12383 for(int32_t i=0; i<8; i++)
12384 {
12385 s->secretcombo[sSWORD+i] = secret_dlg[106+i].d1;
12386 s->secretcset[sSWORD+i] = secret_dlg[106+i].fg;
12387 s->secretflag[sSWORD+i] = secret_dlg[106+i].d2;
12388 }
12389
12390 s->secretcombo[sSTAIRS] = secret_dlg[114].d1;
12391 s->secretcset[sSTAIRS] = secret_dlg[114].fg;
12392 s->secretflag[sSTAIRS] = secret_dlg[114].d2;
12393
12394 s->secretcombo[sREFFIREBALL] = secret_dlg[115].d1;
12395 s->secretcset[sREFFIREBALL] = secret_dlg[115].fg;
12396 s->secretflag[sREFFIREBALL] = secret_dlg[115].d2;
12397
12398 for(int32_t i=0; i<4; i++)
12399 {
12400 s->secretcombo[sHOOKSHOT+i] = secret_dlg[116+i].d1;
12401 s->secretcset[sHOOKSHOT+i] = secret_dlg[116+i].fg;
12402 s->secretflag[sHOOKSHOT+i] = secret_dlg[116+i].d2;
12403 }
12404
12405 for(int32_t i=0; i<16; i++)
12406 {
12407 s->secretcombo[sSECRET01+i] = secret_dlg[120+i].d1;
12408 s->secretcset[sSECRET01+i] = secret_dlg[120+i].fg;
12409 s->secretflag[sSECRET01+i] = secret_dlg[120+i].d2;
12410 }
12411 s->secretflag[sSECNEXT] = secret_dlg[137].d2;
12412
12413 }
12414
12415 return D_O_K;
12416 }
12417
12418 void call_undercombo_dlg(int map, int screen);
12419 int32_t onUnderCombo()
12420 {
12421 call_undercombo_dlg(Map.getCurrMap(), Map.getCurrScr());
12422 return D_O_K;
12423 }
12424
12425 static DIALOG list_dlg[] =
12426 {
12427 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
12428 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12429 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12430 12 { jwin_list_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12431 12 { jwin_button_proc, 90, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
12432 12 { jwin_button_proc, 170, 163, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
12433 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12434 };
12435
12436 /*
12437 typedef struct item_struct {
12438 char *s;
12439 int32_t i;
12440 } item_struct;
12441 */
12442 item_struct bii[MAXITEMS+1];
12443 int32_t bii_cnt=-1;
12444
12445 void build_bii_list(bool usenone)
12446 {
12447 int32_t start=bii_cnt=0;
12448
12449 if(usenone)
12450 {
12451 bii[0].s = (char *)"(None)";
12452 bii[0].i = -2;
12453 bii_cnt=start=1;
12454 }
12455
12456 for(int32_t i=0; i<MAXITEMS; i++)
12457 {
12458 bii[bii_cnt].s = item_string[i];
12459 bii[bii_cnt].i = i;
12460 ++bii_cnt;
12461 }
12462
12463 for(int32_t i=start; i<bii_cnt-1; i++)
12464 {
12465 for(int32_t j=i+1; j<bii_cnt; j++)
12466 {
12467 if(stricmp(bii[i].s,bii[j].s)>0 && strcmp(bii[j].s,""))
12468 {
12469 zc_swap(bii[i],bii[j]);
12470 }
12471 }
12472 }
12473 }
12474
12475 const char *itemlist_num(int32_t index, int32_t *list_size)
12476 {
12477 if(index<0)
12478 {
12479 *list_size = bii_cnt;
12480 return NULL;
12481 }
12482 static char biin_buf[64+6];
12483 if(bii[index].i < 0)
12484 return bii[index].s;
12485 sprintf(biin_buf, "%s (%03d)", bii[index].s, bii[index].i);
12486 return biin_buf;
12487 }
12488
12489 weapon_struct biw[MAXWPNS];
12490 int32_t biw_cnt=-1;
12491
12492 void build_biw_list()
12493 {
12494 int32_t start=biw_cnt=0;
12495
12496 for(int32_t i=start; i<MAXWPNS; i++)
12497 {
12498 biw[biw_cnt].s = (char *)weapon_string[i];
12499 biw[biw_cnt].i = i;
12500 ++biw_cnt;
12501 }
12502
12503 for(int32_t i=start; i<biw_cnt-1; i++)
12504 {
12505 for(int32_t j=i+1; j<biw_cnt; j++)
12506 if(stricmp(biw[i].s,biw[j].s)>0 && strcmp(biw[j].s,""))
12507 zc_swap(biw[i],biw[j]);
12508 }
12509 }
12510
12511 int32_t writeoneweapon(PACKFILE *f, int32_t index)
12512 {
12513 dword section_version=V_WEAPONS;
12514 int32_t zversion = ZELDA_VERSION;
12515 int32_t zbuild = VERSION_BUILD;
12516 int32_t iid = biw[index].i;
12517 al_trace("Writing Weapon Sprite .zwpnspr file for weapon id: %d\n", iid);
12518
12519 //section version info
12520 if(!p_iputl(zversion,f))
12521 {
12522 return 0;
12523 }
12524 if(!p_iputl(zbuild,f))
12525 {
12526 return 0;
12527 }
12528 if(!p_iputw(section_version,f))
12529 {
12530 return 0;
12531 }
12532
12533 if(!write_deprecated_section_cversion(section_version, f))
12534 {
12535 return 0;
12536 }
12537
12538 //weapon string
12539
12540 if(!pfwrite((char *)weapon_string[iid], 64, f))
12541 {
12542 return 0;
12543 }
12544
12545 if(!p_putc(wpnsbuf[iid].misc,f))
12546 {
12547 return 0;
12548 }
12549
12550 if(!p_putc(wpnsbuf[iid].csets,f))
12551 {
12552 return 0;
12553 }
12554
12555 if(!p_putc(wpnsbuf[iid].frames,f))
12556 {
12557 return 0;
12558 }
12559
12560 if(!p_putc(wpnsbuf[iid].speed,f))
12561 {
12562 return 0;
12563 }
12564
12565 if(!p_putc(wpnsbuf[iid].type,f))
12566 {
12567 return 0;
12568 }
12569
12570 if(!p_iputw(wpnsbuf[iid].script,f))
12571 {
12572 return 0;
12573 }
12574
12575 //2.55 starts here
12576 if(!p_iputl(wpnsbuf[iid].tile,f))
12577 {
12578 return 0;
12579 }
12580
12581 return 1;
12582 }
12583
12584
12585 int32_t readoneweapon(PACKFILE *f, int32_t index)
12586 {
12587 dword section_version = 0;
12588 int32_t zversion = 0;
12589 int32_t zbuild = 0;
12590 wpndata tempwpnspr;
12591 memset(&tempwpnspr, 0, sizeof(wpndata));
12592
12593
12594 //char dmapstring[64]={0};
12595 //section version info
12596 if(!p_igetl(&zversion,f))
12597 {
12598 return 0;
12599 }
12600 if(!p_igetl(&zbuild,f))
12601 {
12602 return 0;
12603 }
12604 if(!p_igetw(&section_version,f))
12605 {
12606 return 0;
12607 }
12608 if(!read_deprecated_section_cversion(f))
12609 {
12610 return 0;
12611 }
12612 al_trace("readoneweapon section_version: %d\n", section_version);
12613
12614 if ( zversion > ZELDA_VERSION )
12615 {
12616 al_trace("Cannot read .zwpnspr packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
12617 return 0;
12618 }
12619
12620 else if ( ( section_version > V_WEAPONS ) )
12621 {
12622 al_trace("Cannot read .zwpnspr packfile made using V_WEAPONS (%d)\n", section_version);
12623 return 0;
12624
12625 }
12626 else
12627 {
12628 al_trace("Reading a .zwpnspr packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
12629 }
12630
12631 char tmp_wpn_name[64];
12632 memset(tmp_wpn_name,0,64);
12633 if(!pfread(&tmp_wpn_name, 64, f))
12634 {
12635 return 0;
12636 }
12637
12638 word oldtile = 0;
12639 if(section_version < 8)
12640 if(!p_igetw(&oldtile,f))
12641 return 0;
12642
12643 if(!p_getc(&tempwpnspr.misc,f))
12644 {
12645 return 0;
12646 }
12647
12648 if(!p_getc(&tempwpnspr.csets,f))
12649 {
12650 return 0;
12651 }
12652
12653 if(!p_getc(&tempwpnspr.frames,f))
12654 {
12655 return 0;
12656 }
12657
12658 if(!p_getc(&tempwpnspr.speed,f))
12659 {
12660 return 0;
12661 }
12662
12663 if(!p_getc(&tempwpnspr.type,f))
12664 {
12665 return 0;
12666 }
12667
12668 if(!p_igetw(&tempwpnspr.script,f))
12669 {
12670 return 0;
12671 }
12672
12673 //2.55 starts here
12674 if ( zversion >= 0x255 )
12675 {
12676 if ( section_version >= 7 )
12677 {
12678 if(!p_igetl(&tempwpnspr.tile,f))
12679 {
12680 return 0;
12681 }
12682 }
12683 }
12684 if ( zversion < 0x255 )
12685 {
12686 tempwpnspr.tile = oldtile;
12687 }
12688 ::memcpy( &(wpnsbuf[biw[index].i]),&tempwpnspr, sizeof(wpndata));
12689 ::memcpy(weapon_string[biw[index].i], tmp_wpn_name, 64);
12690
12691 return 1;
12692 }
12693
12694 static int32_t seldata_copy;
12695 static void (*seldata_paste_func)(int32_t, int32_t);
12696
12697 void seldata_rclick_func(int32_t index, int32_t x, int32_t y)
12698 {
12699 NewMenu rcmenu {
12700 { "&Copy", [&](){seldata_copy = index;} },
12701 { "Paste", "&v", [&]()
12702 {
12703 seldata_paste_func(seldata_copy, index);
12704 mark_save_dirty();
12705 }, 0, seldata_copy < 0 ? MFL_DIS : 0 },
12706 };
12707 rcmenu.pop(x, y);
12708 }
12709
12710 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12711 {
12712 if(proc==NULL)
12713 return -1;
12714
12715 list_dlg[0].dp=(void *)prompt;
12716 list_dlg[0].dp2=title_font;
12717 list_dlg[2].d1=index;
12718 ListData select_list(proc, &font);
12719 list_dlg[2].dp=(void *) &select_list;
12720
12721 large_dialog(list_dlg);
12722
12723 seldata_copy=-1;
12724 seldata_paste_func=copyFunc;
12725 if(copyFunc)
12726 {
12727 list_dlg[2].flags|=D_USER<<1;
12728 list_dlg[2].dp3=(void*)seldata_rclick_func;
12729 }
12730 else
12731 {
12732 list_dlg[2].flags&=~(D_USER<<1);
12733 list_dlg[2].dp3=0;
12734 }
12735
12736 int32_t ret=do_zqdialog(list_dlg,2);
12737
12738 if(ret==0||ret==4)
12739 {
12740 position_mouse_z(0);
12741 return -1;
12742 }
12743
12744 return list_dlg[2].d1;
12745 }
12746
12747 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), const char *b1, const char *b2, FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12748 {
12749 if(proc==NULL)
12750 return -1;
12751
12752 list_dlg[0].dp=(void *)prompt;
12753 list_dlg[0].dp2=title_font;
12754 list_dlg[2].d1=index;
12755 ListData select_data_list(proc, &font);
12756 list_dlg[2].dp=(void *) &select_data_list;
12757 list_dlg[3].dp=(void *)b1;
12758 list_dlg[4].dp=(void *)b2;
12759
12760 large_dialog(list_dlg);
12761
12762 seldata_copy=-1;
12763 seldata_paste_func=copyFunc;
12764 if(copyFunc)
12765 {
12766 list_dlg[2].flags|=D_USER<<1;
12767 list_dlg[2].dp3=(void*)seldata_rclick_func;
12768 }
12769 else
12770 {
12771 list_dlg[2].flags&=~(D_USER<<1);
12772 list_dlg[2].dp3=0;
12773 }
12774
12775 int32_t ret = do_zqdialog(list_dlg,2);
12776 list_dlg[3].dp=(void *) "OK";
12777 list_dlg[4].dp=(void *) "Cancel";
12778
12779 if(ret==0||ret==4)
12780 {
12781 position_mouse_z(0);
12782 return -1;
12783 }
12784
12785 position_mouse_z(0);
12786 return list_dlg[2].d1;
12787 }
12788
12789 int32_t onScreenScript()
12790 {
12791 call_screendata_dialog(7);
12792 return D_O_K;
12793 }
12794
12795 int32_t onScrData()
12796 {
12797 restore_mouse();
12798 call_screendata_dialog();
12799 return D_O_K;
12800 }
12801
12802 static char number_str_buf[MIDI_TRACK_BUFFER_SIZE];
12803 int32_t number_list_size=1;
12804 bool number_list_zero=false;
12805
12806 const char *numberlist(int32_t index, int32_t *list_size)
12807 {
12808 if(index>=0)
12809 {
12810 bound(index,0,number_list_size-1);
12811 sprintf(number_str_buf,"%d",index+(number_list_zero?0:1));
12812 return number_str_buf;
12813 }
12814
12815 *list_size=number_list_size;
12816 return NULL;
12817 }
12818
12819 static char dmap_str_buf[37];
12820 int32_t dmap_list_size=MAXDMAPS;
12821 bool dmap_list_zero=true;
12822
12823 const char *dmaplist(int32_t index, int32_t *list_size)
12824 {
12825 if(index>=0)
12826 {
12827 bound(index,0,dmap_list_size-1);
12828 sprintf(dmap_str_buf,"%3d-%s",index+(dmap_list_zero?0:1), DMaps[index].name);
12829 return dmap_str_buf;
12830 }
12831
12832 *list_size=dmap_list_size;
12833 return NULL;
12834 }
12835
12836 const char *gotomaplist(int32_t index, int32_t *list_size)
12837 {
12838 if(index>=0)
12839 {
12840 bound(index,0,map_count-1);
12841 sprintf(number_str_buf,"%d",index+1);
12842 return number_str_buf;
12843 }
12844
12845 *list_size = map_count;
12846 return NULL;
12847 }
12848
12849 const char *midilist(int32_t index, int32_t *list_size)
12850 {
12851 if(index>=0)
12852
12853 {
12854 bound(index,0,MAXCUSTOMMIDIS_ZQ-1);
12855 return midi_string[index];
12856 }
12857
12858 *list_size=MAXCUSTOMMIDIS_ZQ;
12859 return NULL;
12860 }
12861
12862 const char *levelnumlist(int32_t index, int32_t *list_size)
12863 {
12864 if(index>=0)
12865 {
12866 bound(index,0,0xFFF);
12867 sprintf(number_str_buf,"%.3X - %s",index,palnames[index]);
12868 return number_str_buf;
12869 }
12870
12871 *list_size=MAXLEVELS;
12872 return NULL;
12873 }
12874
12875 static char shop_str_buf[40];
12876 int32_t shop_list_size=1;
12877
12878 const char *shoplist(int32_t index, int32_t *list_size)
12879 {
12880 if(index>=0)
12881 {
12882 bound(index,0,shop_list_size-1);
12883 sprintf(shop_str_buf,"%3d: %s",index,QMisc.shop[index].name);
12884 return shop_str_buf;
12885 }
12886
12887 *list_size=shop_list_size;
12888 return NULL;
12889 }
12890
12891 static char bottle_str_buf[40];
12892 int32_t bottle_list_size=1;
12893
12894 const char *bottlelist(int32_t index, int32_t *list_size)
12895 {
12896 if(index>=0)
12897 {
12898 bound(index,0,bottle_list_size-1);
12899 sprintf(bottle_str_buf,"%2d: %s",index+1,QMisc.bottle_types[index].name);
12900 return bottle_str_buf;
12901 }
12902
12903 *list_size=bottle_list_size;
12904 return NULL;
12905 }
12906
12907 static char bottleshop_str_buf[40];
12908 int32_t bottleshop_list_size=1;
12909
12910 const char *bottleshoplist(int32_t index, int32_t *list_size)
12911 {
12912 if(index>=0)
12913 {
12914 bound(index,0,bottleshop_list_size-1);
12915 sprintf(bottleshop_str_buf,"%3d: %s",index,QMisc.bottle_shop_types[index].name);
12916 return bottleshop_str_buf;
12917 }
12918
12919 *list_size=bottleshop_list_size;
12920 return NULL;
12921 }
12922
12923 static char info_str_buf[40];
12924 int32_t info_list_size=1;
12925
12926 const char *infolist(int32_t index, int32_t *list_size)
12927 {
12928 if(index>=0)
12929 {
12930 bound(index,0,info_list_size-1);
12931 sprintf(info_str_buf,"%3d: %s",index,QMisc.info[index].name);
12932 return info_str_buf;
12933 }
12934
12935 *list_size=info_list_size;
12936 return NULL;
12937 }
12938
12939 bool mapcount_will_affect_layers(word newmapcount)
12940 {
12941 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
12942 {
12943 mapscr *layerchecker=&TheMaps[i];
12944
12945 for(int32_t j=0; j<6; j++)
12946 {
12947 if(layerchecker->layermap[j]>(newmapcount))
12948 {
12949 return true;
12950 }
12951 }
12952 }
12953 return false;
12954 }
12955
12956 void update_map_count(word newmapcount)
12957 {
12958 if(map_count == newmapcount) return;
12959 mark_save_dirty();
12960 setMapCount2(newmapcount);
12961 //Prevent the nine 'last mapscreen' buttons from pointing to invlid locations
12962 //if the user reduces the mapcount. -Z ( 23rd September, 2019 )
12963 for ( int32_t q = 0; q < 9; q++ )
12964 {
12965 map_page[q].map = ( map_page[q].map > newmapcount-1 ) ? newmapcount-1 : map_page[q].map;
12966 }
12967 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
12968 {
12969 fix_layers(&TheMaps[i], false);
12970 }
12971
12972 refresh(rMAP+rSCRMAP+rMENU);
12973 }
12974
12975 int32_t onGotoMap()
12976 {
12977 int32_t ret = select_data("Goto Map",Map.getCurrMap(),gotomaplist,get_zc_font(font_lfont));
12978
12979 if(ret >= 0)
12980 {
12981 int32_t m=Map.getCurrMap();
12982 Map.setCurrMap(ret);
12983 }
12984
12985 refresh(rALL);
12986 return D_O_K;
12987 }
12988
12989 int32_t onFlags()
12990 {
12991 restore_mouse();
12992 int32_t ret=select_cflag("Select Combo Flag",Flag);
12993 position_mouse_z(0);
12994
12995 if(ret>=0)
12996 {
12997 Flag=ret;
12998 refresh(rMENU);
12999 doflags();
13000 }
13001
13002 return D_O_K;
13003 }
13004
13005 static DIALOG usedcombo_list_dlg[] =
13006 {
13007 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13008 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combos Used", NULL, NULL },
13009 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13010 12 { jwin_textbox_proc, 72-12, 60+4, 176+24+1, 92+4, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
13011 12 { jwin_button_proc, 130, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13012 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13013 };
13014
13015
13016
13017 int32_t onUsedCombos()
13018 {
13019 restore_mouse();
13020 usedcombo_list_dlg[0].dp2=get_zc_font(font_lfont);
13021
13022 int32_t usedcombos[7][300][2];
13023 char combolist_text[65536];
13024 char temptext[80];
13025
13026 int32_t drawmap=Map.getCurrMap();
13027 int32_t drawscr=Map.getCurrScr();
13028 int32_t counter[7];
13029
13030 for(int32_t layer=0; layer<7; ++layer)
13031 {
13032 counter[layer]=0;
13033
13034 if(layer==0)
13035 {
13036 drawmap=Map.getCurrMap();
13037 drawscr=Map.getCurrScr();
13038 }
13039 else
13040 {
13041 drawmap=Map.CurrScr()->layermap[layer-1]-1;
13042 drawscr=Map.CurrScr()->layerscreen[layer-1];
13043 }
13044 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
13045 if(!draw_mapscr) continue;
13046
13047 usedcombos[layer][0][0]=draw_mapscr->data[0];
13048 usedcombos[layer][0][1]=1;
13049 counter[layer]=1;
13050
13051 for(int32_t i=1; i<176; ++i)
13052 {
13053 bool used=false;
13054
13055 for(int32_t j=0; j<counter[layer]; ++j)
13056 {
13057 if(usedcombos[layer][j][0]==draw_mapscr->data[i])
13058 {
13059 ++usedcombos[layer][j][1];
13060 used=true;
13061 break;
13062 }
13063 }
13064
13065 if(!used)
13066 {
13067 usedcombos[layer][counter[layer]][0]=draw_mapscr->data[i];
13068 usedcombos[layer][counter[layer]][1]=1;
13069 ++counter[layer];
13070 }
13071 }
13072
13073 for(int32_t i=0; i<counter[layer]-1; i++)
13074 {
13075 for(int32_t j=i+1; j<counter[layer]; j++)
13076 {
13077 if(usedcombos[layer][i][0]>usedcombos[layer][j][0])
13078 {
13079 zc_swap(usedcombos[layer][i][0],usedcombos[layer][j][0]);
13080 zc_swap(usedcombos[layer][i][1],usedcombos[layer][j][1]);
13081 }
13082 }
13083 }
13084 }
13085
13086 sprintf(combolist_text, " ");
13087
13088 for(int32_t layer=0; layer<7; ++layer)
13089 {
13090 if(counter[layer]>0)
13091 {
13092 if(layer>0)
13093 {
13094 strcat(combolist_text, "\n");
13095 }
13096
13097 sprintf(temptext, "Combos on layer %d\n-----------------\n", layer);
13098 strcat(combolist_text, temptext);
13099
13100 for(int32_t i=0; i<counter[layer]; i++)
13101 {
13102 if((i<counter[layer]-1) && (((usedcombos[layer][i][1]==usedcombos[layer][i+1][1]&&(usedcombos[layer][i][0]+1==usedcombos[layer][i+1][0])) && ((i==0) || ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))))
13103 {
13104 sprintf(temptext, "%5d ", usedcombos[layer][i][0]);
13105 strcat(combolist_text, temptext);
13106 }
13107 else if(((i>0) && (((usedcombos[layer][i][1]==usedcombos[layer][i-1][1])&&((usedcombos[layer][i][0]-1==usedcombos[layer][i-1][0]))) && ((i==counter[layer]-1) || ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0])))))))
13108 {
13109 sprintf(temptext, "- %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13110 strcat(combolist_text, temptext);
13111 }
13112 else if(((i==0) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))))||
13113 ((i==counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0]))))||
13114 ((i>0) && (i<counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))
13115 {
13116 sprintf(temptext, " %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13117 strcat(combolist_text, temptext);
13118 }
13119 }
13120 }
13121 }
13122
13123 strcat(combolist_text, "\n");
13124 usedcombo_list_dlg[2].dp=combolist_text;
13125 usedcombo_list_dlg[2].d2=0;
13126
13127 large_dialog(usedcombo_list_dlg);
13128
13129 do_zqdialog(usedcombo_list_dlg,2);
13130 position_mouse_z(0);
13131 return D_O_K;
13132 }
13133
13134 int32_t onItem()
13135 {
13136 restore_mouse();
13137 int32_t exit_status;
13138 int32_t current_item=Map.CurrScr()->hasitem != 0 ? Map.CurrScr()->item : -1;
13139
13140 ItemListerDialog(current_item,true).show();
13141 if(current_item != lister_sel_val)
13142 {
13143 if(lister_sel_val>=0)
13144 {
13145 mark_save_dirty();
13146 Map.CurrScr()->item = lister_sel_val;
13147 Map.CurrScr()->hasitem = true;
13148 }
13149 else
13150 {
13151 mark_save_dirty();
13152 Map.CurrScr()->hasitem = false;
13153 }
13154 }
13155
13156 refresh(rMAP+rMENU);
13157 return D_O_K;
13158 }
13159
13160 void call_room_dlg(mapscr* scr);
13161 int32_t onRoom()
13162 {
13163 restore_mouse();
13164 auto* scr = Map.CurrScr();
13165 call_room_dlg(scr);
13166
13167 refresh(rMAP+rMENU);
13168 return D_O_K;
13169 }
13170
13171 int32_t onEndString()
13172 {
13173 int32_t ret=select_data("Select Ending String",QMisc.endstring,msgslist,get_zc_font(font_lfont));
13174
13175 if(ret>=0)
13176 {
13177 mark_save_dirty();
13178 QMisc.endstring=msglistcache[ret];
13179 }
13180
13181 refresh(rMENU);
13182 return D_O_K;
13183 }
13184
13185 12 static ListData levelnum_list(levelnumlist, &font);
13186
13187 static DIALOG screen_pal_dlg[] =
13188 {
13189 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13190 12 { jwin_win_proc, 60-12, 40, 200-16, 96, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Palette", NULL, NULL },
13191 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13192 12 { jwin_droplist_proc, 72-12, 84+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &levelnum_list, NULL, NULL },
13193 12 { jwin_button_proc, 70, 111, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13194 12 { jwin_button_proc, 150, 111, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13195 12 { jwin_text_proc, 72-12, 60+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Note: This does not affect how the", NULL, NULL },
13196 12 { jwin_text_proc, 72-12, 72+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "room will be displayed in-game!", NULL, NULL },
13197 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13198 };
13199 // return list_dlg[2].d1;
13200
13201 int32_t onScreenPalette()
13202 {
13203 restore_mouse();
13204 screen_pal_dlg[0].dp2=get_zc_font(font_lfont);
13205 auto oldcol = screen_pal_dlg[2].d1 = Map.getcolor();
13206
13207 large_dialog(screen_pal_dlg);
13208 auto old_valid = Map.CurrScr()->valid;
13209 pause_dlg_tint(true);
13210 zq_set_screen_never_freeze(true);
13211 while(true)
13212 {
13213 auto ret = do_zqdialog(screen_pal_dlg,2);
13214 if(ret == 2)
13215 {
13216 Map.setcolor(screen_pal_dlg[2].d1);
13217 refresh(rALL);
13218 }
13219 else
13220 {
13221 if(ret == 3)
13222 {
13223 if(screen_pal_dlg[2].d1 != oldcol)
13224 mark_save_dirty();
13225 Map.setcolor(screen_pal_dlg[2].d1);
13226 }
13227 else
13228 {
13229 Map.setcolor(oldcol);
13230 Map.CurrScr()->valid = old_valid;
13231 }
13232 refresh(rALL);
13233 break;
13234 }
13235 }
13236 pause_dlg_tint(false);
13237 zq_set_screen_never_freeze(false);
13238
13239 rebuild_trans_table();
13240
13241 return D_O_K;
13242 }
13243
13244 int32_t onDecScrPal()
13245 {
13246 if(DisableLPalShortcuts)
13247 {
13248 lpal_dsa();
13249 return D_O_K;
13250 }
13251 restore_mouse();
13252 int32_t c = Map.getcolor();
13253 c = (c+511) % 512;
13254 Map.setcolor(c);
13255 refresh(rALL);
13256 mark_save_dirty();
13257 return D_O_K;
13258 }
13259
13260 int32_t onIncScrPal()
13261 {
13262 if(DisableLPalShortcuts)
13263 {
13264 lpal_dsa();
13265 return D_O_K;
13266 }
13267 restore_mouse();
13268 int32_t c = Map.getcolor();
13269 c = (c+1)%512;
13270 Map.setcolor(c);
13271 refresh(rALL);
13272 mark_save_dirty();
13273 return D_O_K;
13274 }
13275
13276 int32_t PalWrap(int32_t kX, int32_t const kLowerBound, int32_t const kUpperBound)
13277 {
13278 int32_t range_size = kUpperBound - kLowerBound + 1;
13279
13280 if (kX < kLowerBound)
13281 kX += range_size * ((kLowerBound - kX) / range_size + 1);
13282
13283 return kLowerBound + (kX - kLowerBound) % range_size;
13284 }
13285
13286 int32_t onDecScrPal16()
13287 {
13288 if(DisableLPalShortcuts)
13289 {
13290 lpal_dsa();
13291 return D_O_K;
13292 }
13293 restore_mouse();
13294 int32_t c = Map.getcolor();
13295 c = PalWrap( ( c-0x10 ), 0, 511 );
13296 Map.setcolor(c);
13297 refresh(rALL);
13298 mark_save_dirty();
13299 return D_O_K;
13300 }
13301
13302 int32_t onIncScrPal16()
13303 {
13304 if(DisableLPalShortcuts)
13305 {
13306 lpal_dsa();
13307 return D_O_K;
13308 }
13309 restore_mouse();
13310 int32_t c = Map.getcolor();
13311 c = PalWrap( ( c+0x10 ), 0, 511 );
13312 Map.setcolor(c);
13313 refresh(rALL);
13314 mark_save_dirty();
13315 return D_O_K;
13316 }
13317
13318 int32_t onZoomIn()
13319 {
13320 change_mapscr_zoom(-1);
13321 return D_O_K;
13322 }
13323
13324 int32_t onZoomOut()
13325 {
13326 change_mapscr_zoom(1);
13327 return D_O_K;
13328 }
13329
13330 int32_t d_ndroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13331 {
13332 int32_t ret = jwin_droplist_proc(msg,d,c);
13333
13334 // The only place this proc is used is in the info type editor.
13335 // If it's ever used anywhere else, this will probably need to be changed.
13336 // Maybe add a flag for it or something.
13337 int32_t msgID=msg_at_pos(d->d1);
13338
13339 switch(msg)
13340 {
13341 case MSG_DRAW:
13342 case MSG_CHAR:
13343 case MSG_CLICK:
13344 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",msgID);
13345 }
13346
13347 return ret;
13348 }
13349
13350 int32_t d_idroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13351 {
13352 int32_t ret = jwin_droplist_proc(msg,d,c);
13353
13354 switch(msg)
13355 {
13356 case MSG_DRAW:
13357 case MSG_CHAR:
13358 case MSG_CLICK:
13359 int32_t tile = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].tile : 0;
13360 int32_t cset = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].csets&15 : 0;
13361 int32_t x = d->x + d->w + 4;
13362 int32_t y = d->y - 8;
13363 int32_t w = 32;
13364 int32_t h = 32;
13365
13366 BITMAP *buf = create_bitmap_ex(8,16,16);
13367 BITMAP *bigbmp = create_bitmap_ex(8,w,h);
13368
13369 if(buf && bigbmp)
13370 {
13371 clear_bitmap(buf);
13372
13373 if(tile)
13374 overtile16(buf, tile,0,0,cset,0);
13375
13376 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, w, h);
13377 destroy_bitmap(buf);
13378 jwin_draw_frame(screen,x,y,w+4,h+4,FR_DEEP);
13379 blit(bigbmp,screen,0,0,x+2,y+2,w,h);
13380 destroy_bitmap(bigbmp);
13381 }
13382
13383 }
13384
13385 return ret;
13386 }
13387
13388 int32_t d_nidroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13389 {
13390 int32_t ret = d_idroplist_proc(msg,d,c);
13391
13392 switch(msg)
13393 {
13394 case MSG_DRAW:
13395 case MSG_CHAR:
13396 case MSG_CLICK:
13397 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",bii[d->d1].i);
13398 }
13399
13400 return ret;
13401 }
13402
13403 // Triforce pieces
13404 static byte triframe_points[9*4] =
13405 {
13406 0,2,2,0, 2,0,4,2, 0,2,4,2, 1,1,3,1, 2,0,2,2,
13407 1,1,1,2, 1,1,2,2, 3,1,3,2, 3,1,2,2
13408 };
13409
13410 int32_t d_tri_frame_proc(int32_t msg,DIALOG *d,int32_t c)
13411 {
13412 //these are here to bypass compiler warnings about unused arguments
13413 c=c;
13414
13415 if(msg==MSG_DRAW)
13416 {
13417 int32_t x[5],y[3];
13418
13419 x[0]=d->x;
13420 x[1]=d->x+(d->w>>2);
13421 x[2]=d->x+(d->w>>1);
13422 x[3]=d->x+(d->w>>1)+(d->w>>2);
13423 x[4]=d->x+d->w;
13424 y[0]=d->y;
13425 y[1]=d->y+(d->h>>1);
13426 y[2]=d->y+d->h;
13427
13428 byte *p = triframe_points;
13429
13430 for(int32_t i=0; i<9; i++)
13431 {
13432 line(screen,x[*p],y[*(p+1)],x[*(p+2)],y[*(p+3)],d->fg);
13433 p+=4;
13434 }
13435 }
13436
13437 return D_O_K;
13438 }
13439
13440 int32_t d_tri_edit_proc(int32_t msg,DIALOG *d,int32_t c)
13441 {
13442 jwin_button_proc(msg,d,c);
13443
13444 if(msg==MSG_CLICK)
13445 {
13446 int v;
13447 if (auto num = call_get_num("Piece Number", d->d1, 8, 1))
13448 v = *num;
13449 else return D_O_K;
13450
13451 if(v!=d->d1)
13452 {
13453 DIALOG *tp = d - d->d2;
13454
13455 for(int32_t i=0; i<8; i++)
13456 {
13457 if(tp->d1==v)
13458 {
13459 tp->d1 = d->d1;
13460 ((char*)(tp->dp))[0] = d->d1+'0';
13461 jwin_button_proc(MSG_DRAW,tp,0);
13462 }
13463
13464 ++tp;
13465 }
13466
13467 d->d1 = v;
13468 ((char*)(d->dp))[0] = v+'0';
13469 }
13470
13471 d->flags = 0;
13472 jwin_button_proc(MSG_DRAW,d,0);
13473 }
13474
13475 return D_O_K;
13476 }
13477
13478 static DIALOG tp_dlg[] =
13479 {
13480 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
13481 12 { jwin_win_proc, 56, 32, 208, 160, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
13482 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13483 12 { d_tri_frame_proc, 64, 56, 192, 96, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, NULL, NULL, NULL },
13484 // 3
13485 12 { d_tri_edit_proc, 138, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
13486 12 { d_tri_edit_proc, 166, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 1, (void *) "2", NULL, NULL },
13487 12 { d_tri_edit_proc, 90, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 2, (void *) "3", NULL, NULL },
13488 12 { d_tri_edit_proc, 214, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 3, (void *) "4", NULL, NULL },
13489 // 7
13490 12 { d_tri_edit_proc, 138, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 4, (void *) "5", NULL, NULL },
13491 12 { d_tri_edit_proc, 118, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 5, (void *) "6", NULL, NULL },
13492 12 { d_tri_edit_proc, 166, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 6, (void *) "7", NULL, NULL },
13493 12 { d_tri_edit_proc, 186, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 7, (void *) "8", NULL, NULL },
13494 // 11
13495 12 { jwin_button_proc, 90, 166, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13496 12 { jwin_button_proc, 170, 166, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13497 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13498 };
13499
13500 int32_t onTriPieces()
13501 {
13502 tp_dlg[0].dp2=get_zc_font(font_lfont);
13503 char temptext[8][2];
13504
13505 for(int32_t i=0; i<8; i++)
13506 {
13507 tp_dlg[i+3].d1 = QMisc.triforce[i];
13508 // ((char*)(tp_dlg[i+3].dp))[0] = QMisc.triforce[i]+'0';
13509 sprintf(temptext[i], "%d", QMisc.triforce[i]);
13510 tp_dlg[i+3].dp=temptext[i];
13511 }
13512
13513 large_dialog(tp_dlg);
13514
13515 if(do_zqdialog(tp_dlg,-1) == 11)
13516 {
13517 mark_save_dirty();
13518
13519 for(int32_t i=0; i<8; i++)
13520 QMisc.triforce[i] = tp_dlg[i+3].d1;
13521 }
13522
13523 return D_O_K;
13524 }
13525
13526 bool small_dmap=false;
13527
13528 int32_t d_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
13529 {
13530 return jwin_hexedit_proc(msg,d,c);
13531 }
13532
13533 void drawgrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13534 {
13535 if(div!=-1)
13536 rectfill(dest,x-1,y-1,x+63,y+3,div);
13537
13538 for(int32_t dx=0; dx<64; dx+=8)
13539 {
13540 if(grid&0x80)
13541 rectfill(dest,x+dx,y,x+dx+6,y+2,fg);
13542 else if(bg!=-1)
13543 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13544
13545 grid<<=1;
13546 }
13547 }
13548
13549 void drawovergrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t color,int32_t div)
13550 {
13551 if(div!=-1)
13552 rectfill(dest,x-1,y-1,x+63,y+3,div);
13553
13554 for(int32_t dx=0; dx<64; dx+=4)
13555 {
13556 rectfill(dest,x+dx,y,x+dx+2,y+2,color);
13557 grid<<=1;
13558 }
13559 }
13560
13561 void drawgrid_s(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13562 {
13563 rectfill(dest,x-1,y-1,x+63,y+3,div);
13564
13565 for(int32_t dx=0; dx<64; dx+=8)
13566 {
13567 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13568
13569 if(grid&0x80)
13570 rectfill(dest,x+dx+2,y,x+dx+4,y+2,fg);
13571
13572 grid<<=1;
13573 }
13574 }
13575
13576 void drawdmap(int32_t dmap)
13577 {
13578 int32_t c;
13579 zcolors mc=QMisc.colors;
13580
13581 switch((DMaps[dmap].type&dmfTYPE))
13582 {
13583 case dmDNGN:
13584 case dmCAVE:
13585 clear_bitmap(dmapbmp_small);
13586
13587 if(DMaps[dmap].minimap_tile[1])
13588 ;
13589 // overworld_map_tile overrides the NES minimap. dungeon_map_tile does not.
13590 else for(int32_t y=1; y<33; y+=4)
13591 drawgrid(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2], DMaps[dmap].flags&dmfMINIMAPCOLORFIX ? mc.cave_fg : mc.dngn_fg, -1, -1);
13592
13593 c=DMaps[dmap].compass;
13594 // rectfill(dmapbmp,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,dvc(2*4));
13595 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(4));
13596 c=DMaps[dmap].cont;
13597 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13598 break;
13599
13600 case dmOVERW:
13601 clear_bitmap(dmapbmp_small);
13602
13603 if(DMaps[dmap].minimap_tile[1])
13604 ;
13605 else if(!mc.overworld_map_tile)
13606 for(int32_t y=1; y<33; y+=4)
13607 drawovergrid(dmapbmp_small,1,y,DMaps[dmap].grid[y>>2],mc.overw_bg,vc(0));
13608
13609 c=DMaps[dmap].cont;
13610 rectfill(dmapbmp_small,(c&15)*4+1,(c>>4)*4+1,(c&15)*4+3,(c>>4)*4+3,vc(10));
13611 break;
13612
13613 case dmBSOVERW:
13614 clear_bitmap(dmapbmp_small);
13615
13616 if(DMaps[dmap].minimap_tile[1])
13617 ;
13618 else if(!mc.overworld_map_tile)
13619 for(int32_t y=1; y<33; y+=4)
13620 // drawgrid_s(dmapbmp,1,y,DMaps[dmap].grid[y>>2],dvc(2*4),dvc(2*3),dvc(3+4));
13621 drawgrid_s(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2],mc.bs_goal,mc.bs_dk,vc(14));
13622
13623 c=DMaps[dmap].cont;
13624 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13625 break;
13626 }
13627 }
13628
13629 void drawdmap_screen(int32_t x, int32_t y, int32_t w, int32_t h, int32_t dmap)
13630 {
13631 BITMAP *tempbmp = create_bitmap_ex(8,w,h);
13632 clear_to_color(tempbmp, vc(0));
13633 zcolors mc=QMisc.colors;
13634
13635 // rectfill(tempbmp,x,y,x+w-1,y+h-1,vc(0));
13636
13637 if(DMaps[dmap].minimap_tile[1])
13638 {
13639 draw_block(tempbmp,0,0,DMaps[dmap].minimap_tile[1],DMaps[dmap].minimap_cset[1],5,3);
13640 }
13641 else if(((DMaps[dmap].type&dmfTYPE)==dmDNGN || (DMaps[dmap].type&dmfTYPE)==dmCAVE) && mc.dungeon_map_tile)
13642 {
13643 draw_block(tempbmp,0,0,mc.dungeon_map_tile,mc.dungeon_map_cset,5,3);
13644 }
13645 else if(((DMaps[dmap].type&dmfTYPE)==dmOVERW || (DMaps[dmap].type&dmfTYPE)==dmBSOVERW) && mc.overworld_map_tile)
13646 {
13647 draw_block(tempbmp,0,0,mc.overworld_map_tile,mc.overworld_map_cset,5,3);
13648 }
13649
13650 masked_blit(dmapbmp_small,tempbmp,0,0,8,7,65,33);
13651
13652 blit(tempbmp,screen,0,0,x,y,w,h);
13653 destroy_bitmap(tempbmp);
13654
13655 }
13656
13657 int32_t d_dropdmaplist_proc(int32_t msg,DIALOG *d,int32_t c)
13658 {
13659 if(msg==MSG_DRAW)
13660 {
13661 int32_t dmap = d->d1;
13662 int32_t *xy = (int32_t*)(d->dp3);
13663 float temp_scale = 1.5;
13664
13665 drawdmap(dmap);
13666
13667 if(xy[0]>-1000&&xy[1]>-1000)
13668 {
13669 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
13670 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
13671 int32_t w = 84;
13672 int32_t h = 52;
13673 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
13674 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
13675 }
13676
13677 if(xy[2]>-1000&&xy[3]>-1000)
13678 {
13679 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[2])*temp_scale),d->y+int32_t((xy[3])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %-3d",DMaps[d->d1].map+1);
13680 }
13681
13682 if(xy[4]>-1000&&xy[5]>-1000)
13683 {
13684 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[4])*temp_scale),d->y+int32_t((xy[5])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level: %-3d",DMaps[d->d1].level);
13685 }
13686 }
13687
13688 return jwin_droplist_proc(msg,d,c);
13689 }
13690
13691 void drawxmap(ALLEGRO_BITMAP* dest, int32_t themap, int32_t xoff, bool large, int dx, int dy)
13692 {
13693 ALLEGRO_STATE old_state;
13694 al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP);
13695
13696 al_set_target_bitmap(dest);
13697 al_clear_to_color(al_map_rgba(0, 0, 0, 0));
13698
13699 int32_t cols = (large ? 8 : 16);
13700 int32_t col_width = large ? 22 : 11;
13701 int32_t dot_width = (large ? 6 : 4);
13702 int32_t dot_offset = (large ? 7 : 3);
13703 int32_t l = 10;
13704
13705 for (int32_t y = 0; y < 8; y++)
13706 {
13707 // Users might have set the dmap to a map that has since been deleted.
13708 if (themap >= Map.getMapCount())
13709 break;
13710
13711 for (int32_t x = 0; x < cols; x++)
13712 {
13713 if (x + xoff < 0 || x + xoff > 15)
13714 continue;
13715
13716 const mapscr* scr = get_canonical_scr(themap, y * 16 + x + (large ? xoff : 0));
13717 if (!(scr->valid & mVALID))
13718 continue;
13719
13720 al_draw_filled_rectangle(dx + (x * col_width), dy + (y * l), dx + (x * col_width + col_width), dy + ((y * l) + l), real_lc1(scr->color));
13721 al_draw_filled_rectangle(dx + (x * col_width + dot_offset), dy + (y * l + 3), dx + (x * col_width + dot_offset + dot_width), dy + (y * l + l - 3), real_lc2(scr->color));
13722 }
13723 }
13724
13725 al_restore_state(&old_state);
13726 }
13727
13728 12 ListData dmap_list(dmaplist, &font);
13729
13730 12 static dmap copiedDMap;
13731 static byte dmapcopied = 0;
13732
13733 int32_t writesomedmaps(PACKFILE *f, int32_t first, int32_t last, int32_t max)
13734 {
13735
13736 dword section_version=V_DMAPS;
13737 int32_t zversion = ZELDA_VERSION;
13738 int32_t zbuild = VERSION_BUILD;
13739
13740 if(!p_iputl(V_ZDMAP,f))
13741 {
13742 return 0;
13743 }
13744
13745 //section version info
13746 if(!p_iputl(zversion,f))
13747 {
13748 return 0;
13749 }
13750 if(!p_iputl(zbuild,f))
13751 {
13752 return 0;
13753 }
13754 if(!p_iputw(section_version,f))
13755 {
13756 new_return(2);
13757 }
13758
13759 if(!write_deprecated_section_cversion(section_version, f))
13760 {
13761 new_return(3);
13762 }
13763 //max possible at this time
13764 if(!p_iputl(max,f))
13765 {
13766 new_return(4);
13767 }
13768 //first id written
13769 if(!p_iputl(first,f))
13770 {
13771 new_return(5);
13772 }
13773 //last id written
13774 if(!p_iputl(last,f))
13775 {
13776 new_return(6);
13777 }
13778 int32_t count = last-first;
13779 //number written
13780 if(!p_iputl(count,f))
13781 {
13782 new_return(7);
13783 }
13784
13785
13786 for ( int32_t i = first; i <= last; ++i )
13787 {
13788 if ( i > max ) break;
13789
13790 if (int ret = write_one_dmap(f, i))
13791 return ret;
13792 }
13793
13794 return 1;
13795 }
13796
13797 int32_t readsomedmaps(PACKFILE *f)
13798 {
13799 dword section_version = 0;
13800 int32_t zversion = 0;
13801 int32_t zbuild = 0;
13802 dmap tempdmap{};
13803
13804 int32_t first = 0, last = 0, max = 0, count = 0;
13805 int32_t datatype_version = 0;
13806
13807 //char dmapstring[64]={0};
13808 //section version info
13809 if(!p_igetl(&datatype_version,f))
13810 {
13811 return 0;
13812 }
13813 if ( datatype_version < 0 )
13814 {
13815 if(!p_igetl(&zversion,f))
13816 {
13817 return 0;
13818 }
13819 }
13820 else
13821 {
13822 zversion = datatype_version;
13823 }
13824 if(!p_igetl(&zbuild,f))
13825 {
13826 return 0;
13827 }
13828
13829 if(!p_igetw(&section_version,f))
13830 {
13831 return 0;
13832 }
13833
13834 if(!read_deprecated_section_cversion(f))
13835 {
13836 return 0;
13837 }
13838 if ( datatype_version < 0 )
13839 {
13840 if(!p_igetl(&max,f))
13841 {
13842 return 0;
13843 }
13844 if(!p_igetl(&first,f))
13845 {
13846 return 0;
13847 }
13848 if(!p_igetl(&last,f))
13849 {
13850 return 0;
13851 }
13852 if(!p_igetl(&count,f))
13853 {
13854 return 0;
13855 }
13856 }
13857 else
13858 {
13859 first = 0;
13860 last = 0;
13861 count = 1;
13862 max = 255;
13863 }
13864
13865
13866
13867
13868 al_trace("readsomedmaps section_version: %d\n", section_version);
13869
13870 if ( zversion > ZELDA_VERSION )
13871 {
13872 al_trace("Cannot read .zdmap packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
13873 return 0;
13874 }
13875 else if (( section_version > V_DMAPS ))
13876 {
13877 al_trace("Cannot read .zdmap packfile made using V_DMAPS (%d)\n", section_version);
13878 return 0;
13879 }
13880 else
13881 {
13882 al_trace("Reading a .zdmap packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
13883 }
13884 //if(!pfread(&dmapstring, 64, f))
13885 //{
13886 // return 0;
13887 //}
13888 for ( int32_t i = first; i <= last; ++i )
13889 {
13890 if (int ret = read_one_dmap(f, &header, section_version, i))
13891 return ret;
13892 }
13893 return 1;
13894 }
13895
13896 int32_t onDmaps()
13897 {
13898 DMapListerDialog(0).show();
13899 return D_O_K;
13900 }
13901
13902 int32_t onMaps()
13903 {
13904 call_edit_map_settings(Map.getCurrMap());
13905 return D_O_K;
13906 }
13907
13908 int32_t onMidis()
13909 {
13910 stopMusic();
13911 MidiListerDialog().show();
13912 return D_O_K;
13913 }
13914
13915 const char *warptypelist(int32_t index, int32_t *list_size)
13916 {
13917 if(index>=0)
13918 {
13919 if(index>=MAXWARPTYPES)
13920 index=MAXWARPTYPES-1;
13921
13922 return warptype_string[index];
13923 }
13924
13925 *list_size=MAXWARPTYPES;
13926 // *list_size=6;
13927 return NULL;
13928 }
13929
13930 const char *warpeffectlist(int32_t index, int32_t *list_size)
13931 {
13932 if(index>=0)
13933 {
13934 if(index>=MAXWARPEFFECTS)
13935 index=MAXWARPEFFECTS-1;
13936
13937 return warpeffect_string[index];
13938 }
13939
13940 *list_size=MAXWARPEFFECTS;
13941 return NULL;
13942 }
13943
13944 static int32_t warp1_list[] =
13945 {
13946 2,3,4,5,6,7,8,9,10,11,12,13,53,54,63,67,-1
13947 };
13948
13949 static int32_t warp2_list[] =
13950 {
13951 17,18,19,20,21,22,23,24,25,26,27,28,55,56,64,68,-1
13952 };
13953
13954 static int32_t warp3_list[] =
13955 {
13956 29,30,31,32,33,34,35,36,37,38,39,40,57,58,65,69,-1
13957 };
13958
13959 static int32_t warp4_list[] =
13960 {
13961 41,42,43,44,45,46,47,48,49,50,51,52,59,60,66,70,-1
13962 };
13963
13964 static TABPANEL warp_tabs[] =
13965 {
13966 // (text)
13967 { (char *)"A", D_SELECTED, warp1_list, 0, NULL },
13968 { (char *)"B", 0, warp2_list, 0, NULL },
13969 { (char *)"C", 0, warp3_list, 0, NULL },
13970 { (char *)"D", 0, warp4_list, 0, NULL },
13971 { NULL, 0, NULL, 0, NULL }
13972 };
13973
13974 int32_t onTileWarpIndex(int32_t index)
13975 {
13976 int32_t i=-1;
13977
13978 while(warp_tabs[++i].text != NULL)
13979 warp_tabs[i].flags = (i==index ? D_SELECTED : 0);
13980
13981 onTileWarp();
13982 return D_O_K;
13983 }
13984
13985 static char warpr_buf[10];
13986 const char *warprlist(int32_t index, int32_t *list_size)
13987 {
13988 if(index>=0)
13989 {
13990 bound(index,0,3);
13991 sprintf(warpr_buf,"%c",index+0x41);
13992 return warpr_buf;
13993 }
13994
13995 *list_size=4;
13996 return NULL;
13997 }
13998
13999 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t c);
14000
14001 12 static ListData warp_dlg_list(warptypelist, &font);
14002 12 static ListData warp_ret_list(warprlist, &font);
14003
14004 int32_t d_warpdestscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
14005 {
14006 if(msg == MSG_START)
14007 {
14008 d->d1 = -1; //cached val
14009 d->d2 = -1; //cached dmap
14010 d->fg = 0; //cached 'force_16'
14011 }
14012 char* buf = (char*)d->dp;
14013 vector<DIALOG*>* dlgs = (vector<DIALOG*>*)d->dp2;
14014 int* dmap_ptr = (int*) d->dp3;
14015 if(!(buf && dmap_ptr))
14016 return D_O_K;
14017 bool is_overworld = ((DMaps[*dmap_ptr].type&dmfTYPE)==dmOVERW);
14018 int scrw = is_overworld ? 16 : 8, scrh = 9;
14019 const int max = 0x87;
14020 int bufval = zc_xtoi(buf);
14021 int val = vbound(bufval,0,max);
14022 auto& dm = DMaps[*dmap_ptr];
14023 auto val_offset = dm.xoff < 0 ? -dm.xoff : 0;
14024 bool force_16 = d->fg;
14025 if(!is_overworld)
14026 {
14027 if((val&0xF) >= 0x8)
14028 force_16 = true;
14029 else if((val&0xF) < val_offset && (val&0xF0) < 0x80)
14030 force_16 = true;
14031 }
14032 if(force_16) //can't bound, some quests need to warp out of bounds... -Em
14033 {
14034 scrw = 16; //just force show the larger grid instead
14035 val_offset = 0;
14036 }
14037
14038 int xscl = d->w/scrw;
14039 int yscl = d->h/scrh;
14040
14041 int ret = D_O_K;
14042 bool redraw = false;
14043 if(d->d1 != val)
14044 {
14045 redraw = true;
14046 d->d1 = val;
14047 }
14048 if(bufval != val)
14049 {
14050 redraw = true;
14051 sprintf(buf, "%X", val);
14052 }
14053 if(d->d2 != *dmap_ptr)
14054 {
14055 redraw = true;
14056 d->d2 = *dmap_ptr;
14057 }
14058 switch(msg)
14059 {
14060 case MSG_WANTFOCUS:
14061 ret = D_WANTFOCUS;
14062 break;
14063 case MSG_CLICK:
14064 {
14065 d->fg = force_16 ? 1 : 0;
14066 bool redraw2 = false;
14067 while(gui_mouse_b())
14068 {
14069 if(redraw2)
14070 {
14071 broadcast_dialog_message(MSG_DRAW, 0);
14072 redraw2 = false;
14073 }
14074 if(!d->fg && (gui_mouse_b()&2))
14075 {
14076 scrw = 16;
14077 xscl = d->w/scrw;
14078 yscl = d->h/scrh;
14079 val_offset = 0;
14080 d->fg = 1;
14081 redraw2 = true;
14082 }
14083 custom_vsync();
14084 if(!mouse_in_rect(d->x,d->y,d->w,d->h))
14085 continue;
14086 int mx = gui_mouse_x()-d->x, my = gui_mouse_y()-d->y;
14087 int y = vbound(my/yscl,0,scrh-1);
14088 auto offs = y==8 ? 0 : val_offset;
14089 int x = vbound(mx/xscl,offs,scrw-1);
14090 auto val2 = (y*16)+x;
14091 if(val2 > max) //out of bounds in the bottom-right
14092 continue;
14093 val = val2;
14094 if(d->d1 != val)
14095 {
14096 d->d1 = val;
14097 sprintf(buf, "%02X", val);
14098 redraw2 = true;
14099 }
14100 }
14101 redraw = true;
14102 d->fg = 0;
14103 break;
14104 }
14105 case MSG_DRAW:
14106 {
14107 rectfill(screen,d->x,d->y,d->x+d->w-1,d->y+d->h-1,jwin_pal[jcBOX]);
14108 jwin_draw_frame(screen, d->x-2, d->y-2, d->w+4, d->h+4, FR_MENU);
14109 for(int yind = 0; yind < scrh; ++yind)
14110 {
14111 auto gr = (yind < 8 ? dm.grid[yind] : 0);
14112 for(int xind = (yind == 8 ? 0 : val_offset); xind < scrw; ++xind)
14113 {
14114 int screen_index = xind+(yind*16);
14115 if(screen_index > max)
14116 continue;
14117 int fr = FR_MENU;
14118 if(screen_index == d->d1)
14119 fr = FR_GREEN;
14120 else if(!is_overworld && xind < 8 && (gr&(1<<(8-xind-1))))
14121 fr = FR_MENU_INV;
14122 jwin_draw_frame(screen, d->x+(xind*xscl), d->y+(yind*yscl), xscl, yscl, fr);
14123 }
14124 }
14125 break;
14126 }
14127 case MSG_XCHAR:
14128 {
14129 bool on_80 = (val&0xF0) == 0x80;
14130 switch(c>>8)
14131 {
14132 case KEY_UP:
14133 if((val&0xF0) && !(val_offset && on_80 && (val&0xF) < val_offset))
14134 {
14135 val -= 0x10;
14136 redraw = true;
14137 }
14138 ret |= D_USED_CHAR;
14139 break;
14140 case KEY_DOWN:
14141 if((val&0xF0) < ((val&0xF) < 0x8 ? 0x80 : 0x70))
14142 {
14143 val += 0x10;
14144 redraw = true;
14145 }
14146 ret |= D_USED_CHAR;
14147 break;
14148 case KEY_LEFT:
14149 if((val&0xF) > (on_80 ? 0 : val_offset))
14150 {
14151 --val;
14152 redraw = true;
14153 }
14154 ret |= D_USED_CHAR;
14155 break;
14156 case KEY_RIGHT:
14157 if((val&0xF) < scrw-1 && val < 0x87)
14158 {
14159 ++val;
14160 redraw = true;
14161 }
14162 ret |= D_USED_CHAR;
14163 break;
14164 }
14165 if(redraw)
14166 sprintf(buf, "%02X", val);
14167 break;
14168 }
14169 }
14170 if(redraw)
14171 {
14172 if(msg == MSG_IDLE)
14173 broadcast_dialog_message(MSG_DRAW,0);
14174 else
14175 {
14176 d->d1 = d->d2 = -1;
14177 object_message(d,MSG_IDLE,0);
14178 }
14179 }
14180
14181 return ret;
14182 }
14183
14184 int32_t tilewarpdmapxy[6] = {170,38,170,18,170,27};
14185 static DIALOG tilewarp_dlg[] =
14186 {
14187 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
14188 12 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
14189 12 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
14190 12 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
14191 12 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
14192 12 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
14193 //5
14194 12 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
14195 12 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
14196 12 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
14197 12 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
14198 12 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
14199 //10
14200 12 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
14201 12 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
14202 12 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
14203 12 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
14204 12 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
14205 //15
14206 12 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
14207 12 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
14208 12 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
14209 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
14210 };
14211
14212 int32_t sidewarpdmapxy[6] = {170,38,170,18,170,27};
14213 static DIALOG sidewarp_dlg[] =
14214 {
14215 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
14216 12 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
14217 12 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
14218 12 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
14219 12 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
14220 12 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
14221 //5
14222 12 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
14223 12 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
14224 12 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
14225 12 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
14226 12 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
14227 //10
14228 12 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
14229 12 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
14230 12 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
14231 12 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
14232 12 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
14233 //15
14234 12 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
14235 12 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
14236 12 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
14237 // 18
14238 12 { d_wflag_proc, 18, 17, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
14239 12 { d_wflag_proc, 18, 47, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
14240 // 20
14241 12 { d_wflag_proc, 8, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
14242 12 { d_wflag_proc, 37, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
14243
14244 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
14245 };
14246
14247 int32_t warpringxy[6] = {170,38,170,18,170,27};
14248 static DIALOG warpring_warp_dlg[] =
14249 {
14250 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
14251 12 { jwin_win_proc, 0, 0, 302, 145, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
14252 12 { jwin_rtext_proc, 57, 25, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
14253 12 { jwin_rtext_proc, 57, 46, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
14254 12 { d_dropdmaplist_proc, 59, 19, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, warpringxy },
14255 12 { jwin_hexedit_proc, 59, 39, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
14256 // 5
14257 12 { jwin_button_proc, 61, 115, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
14258 12 { jwin_button_proc, 121, 115, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
14259 12 { jwin_button_proc, 181, 115, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
14260 12 { d_warpdestscrsel_proc, 90, 39, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
14261
14262 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
14263 };
14264
14265 // Side warp flag procedure
14266 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t)
14267 {
14268 int32_t ret = D_O_K;
14269 switch(msg)
14270 {
14271 case MSG_DRAW:
14272 {
14273 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
14274
14275 if(d->d1==1)
14276 {
14277 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
14278 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
14279
14280 if(d->flags&D_SELECTED)
14281 {
14282 int32_t e=d->d2&3;
14283
14284 if(d->w>d->h)
14285 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
14286 else
14287 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
14288 }
14289
14290 }
14291 else
14292 {
14293 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
14294 }
14295 }
14296 break;
14297
14298 case MSG_CLICK:
14299 {
14300 if(d->flags & D_DISABLED)
14301 return D_O_K;
14302 bool rclick = gui_mouse_b() & 2;
14303 if(d->d1==1)
14304 {
14305 if(!(d->flags&D_SELECTED))
14306 {
14307 d->flags |= D_SELECTED;
14308 d->d2 &= 0x80;
14309 if (rclick)
14310 d->d2 |= 3;
14311 }
14312 else
14313 {
14314 if((d->d2&3) == (rclick?0:3))
14315 {
14316 d->flags ^= D_SELECTED;
14317 d->d2 &= 0x80;
14318 }
14319 else
14320 {
14321 int32_t f = d->d2&3;
14322 d->d2 &= 0x80;
14323 f += rclick ? -1 : 1;
14324 d->d2 |= f;
14325 }
14326 }
14327 }
14328 else
14329 {
14330 d->flags^=D_SELECTED;
14331 }
14332
14333 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
14334
14335 if(d->d1==1)
14336 {
14337 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
14338 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
14339
14340 if(d->flags&D_SELECTED)
14341 {
14342 int32_t e=d->d2&3;
14343
14344 if(d->w>d->h)
14345 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
14346 else
14347 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
14348 }
14349 }
14350 else
14351 {
14352 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
14353 }
14354
14355
14356 while(gui_mouse_b())
14357 {
14358 /* do nothing */
14359 rest(1);
14360 }
14361 ret = D_REDRAWME;
14362 }
14363 break;
14364 }
14365
14366 return ret;
14367 }
14368
14369 int32_t d_dmapscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
14370 {
14371 //these are here to bypass compiler warnings about unused arguments
14372 c=c;
14373
14374 int32_t ret = D_O_K;
14375
14376 switch(msg)
14377 {
14378 case MSG_CLICK:
14379 sprintf((char*)((d+2)->dp),"%X%X",vbound((gui_mouse_y()-d->y)/4,0,7),vbound((gui_mouse_x()-d->x)/(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?4:8),0,(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?15:7)));
14380 object_message(d+2, MSG_DRAW, 0);
14381 break;
14382 }
14383
14384 return ret;
14385 }
14386
14387 int32_t warpdestsel_x=-1;
14388 int32_t warpdestsel_y=-1;
14389 int32_t warpdestmap=-1;
14390 int32_t warpdestscr=-1;
14391
14392 int32_t jwin_minibutton_proc(int32_t msg,DIALOG *d,int32_t c)
14393 {
14394 switch(msg)
14395 {
14396 case MSG_DRAW:
14397 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, false);
14398 return D_O_K;
14399 break;
14400 }
14401
14402 return jwin_button_proc(msg,d,c);
14403 }
14404
14405 int32_t d_triggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
14406 {
14407 static BITMAP *dummy=create_bitmap_ex(8, 1, 1);
14408
14409 switch(msg)
14410 {
14411 case MSG_START:
14412 d->w=gui_textout_ln(dummy, font, (uint8_t *)d->dp, 0, 0, jwin_pal[jcMEDDARK], -1, 0)+4;
14413 d->h=text_height(font)+5;
14414 break;
14415
14416 case MSG_GOTFOCUS:
14417 d->flags&=~D_GOTFOCUS;
14418 break;
14419
14420 }
14421
14422 return jwin_minibutton_proc(msg,d,c);
14423 }
14424
14425 int32_t d_alltriggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
14426 {
14427 DIALOG *temp_d;
14428 int32_t ret=d_triggerbutton_proc(msg,d,c);
14429
14430 switch(msg)
14431 {
14432 case MSG_CLICK:
14433 temp_d=d-1;
14434
14435 while(temp_d->proc==d_triggerbutton_proc)
14436 {
14437 temp_d->flags&=~D_SELECTED;
14438 temp_d->flags|=D_DIRTY;
14439
14440 if(d->flags&D_SELECTED)
14441 {
14442 temp_d->flags|=D_SELECTED;
14443 }
14444
14445 --temp_d;
14446 }
14447
14448 break;
14449 }
14450
14451 return ret;
14452 }
14453
14454 int32_t d_ticsedit_proc(int32_t msg,DIALOG *d,int32_t c)
14455 {
14456 int32_t ret = jwin_edit_proc(msg,d,c);
14457
14458 if(msg==MSG_DRAW)
14459 {
14460 int32_t tics=vbound(atoi((char*)d->dp),0,65535);
14461 sprintf((char*)(d+1)->dp,"%s %s",ticksstr(tics),tics==0?"(No Timed Warp)":" ");
14462 object_message(d+1,MSG_DRAW,c);
14463 }
14464
14465 return ret;
14466 }
14467
14468 12 static ListData warp_effect_list(warpeffectlist,&font);
14469
14470 struct tw_data
14471 {
14472 int twscr[4], twtype[4], twdmap[4], wret[4];
14473 byte oflags;
14474 optional<uint> loaded;
14475
14476 tw_data(mapscr* scr) {load_scr(scr);}
14477 void load_scr(mapscr* scr)
14478 {
14479 oflags = scr->tilewarpoverlayflags;
14480 for(int q = 0; q < 4; ++q)
14481 {
14482 twscr[q] = scr->tilewarpscr[q];
14483 twtype[q] = scr->tilewarptype[q];
14484 twdmap[q] = scr->tilewarpdmap[q];
14485 wret[q] = (scr->warpreturnc >> (2*q))&3;
14486 }
14487 loaded.reset();
14488 }
14489 void save_scr(mapscr* scr)
14490 {
14491 mark_save_dirty();
14492 scr->tilewarpoverlayflags = oflags;
14493 scr->warpreturnc = scr->warpreturnc & 0xFF00;
14494 for(int q = 0; q < 4; ++q)
14495 {
14496 scr->tilewarpscr[q] = twscr[q];
14497 scr->tilewarptype[q] = twtype[q];
14498 scr->tilewarpdmap[q] = twdmap[q];
14499 scr->warpreturnc |= wret[q] << (2*q);
14500 }
14501 }
14502
14503 void load(uint ind)
14504 {
14505 if(ind >= 4) return;
14506 loaded = ind;
14507 tilewarp_dlg[4].d1 = twtype[ind];
14508 tilewarp_dlg[5].d1 = twdmap[ind];
14509 char* buf = (char*)tilewarp_dlg[6].dp;
14510 sprintf(buf,"%02X",twscr[ind]);
14511 tilewarp_dlg[11].d1 = wret[ind];
14512 SETFLAG(tilewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
14513 for(int q = 0; q < 4; ++q)
14514 SETFLAG(tilewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
14515 }
14516 void save(uint ind)
14517 {
14518 if(ind >= 4) return;
14519 twtype[ind] = tilewarp_dlg[4].d1;
14520 twdmap[ind] = tilewarp_dlg[5].d1;
14521 char* buf = (char*)tilewarp_dlg[6].dp;
14522 twscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
14523 wret[ind] = tilewarp_dlg[11].d1;
14524 set_bit(&oflags, ind, tilewarp_dlg[12].flags & D_SELECTED);
14525 }
14526 void save()
14527 {
14528 if(loaded)
14529 save(*loaded);
14530 }
14531 void swap(uint ind)
14532 {
14533 if(ind >= 4) return;
14534 if(loaded)
14535 {
14536 save(*loaded);
14537 if(*loaded == ind)
14538 return;
14539 }
14540 load(ind);
14541 }
14542 };
14543 int32_t onTileWarp()
14544 {
14545 restore_mouse();
14546 tilewarp_dlg[0].dp=(void *) "Tile Warp";
14547 tilewarp_dlg[0].dp2=get_zc_font(font_lfont);
14548
14549 mapscr* mptr = Map.CurrScr();
14550 char buf[10];
14551 tilewarp_dlg[6].dp=buf;
14552 tilewarp_dlg[13].dp = buf;
14553 tilewarp_dlg[13].dp3 = &tilewarp_dlg[5].d1;
14554
14555 vector<DIALOG*> dlgs;
14556 dlgs.push_back(&tilewarp_dlg[5]);
14557 dlgs.push_back(&tilewarp_dlg[6]);
14558 tilewarp_dlg[13].dp2 = &dlgs;
14559
14560 tw_data data(mptr);
14561 data.load(0);
14562
14563 dmap_list_size=MAXDMAPS;
14564 dmap_list_zero=true;
14565
14566 large_dialog(tilewarp_dlg);
14567
14568 bool running = true;
14569 int ret;
14570 do
14571 {
14572 ret = do_zqdialog(tilewarp_dlg,-1);
14573 switch(ret)
14574 {
14575 // OK, GO
14576 case 7: case 8:
14577 running = false;
14578 data.save();
14579 data.save_scr(mptr);
14580 refresh(rMENU);
14581 break;
14582 //Cancel
14583 case 9:
14584 running = false;
14585 break;
14586 //A,B,C,D
14587 case 14: case 15: case 16: case 17:
14588 data.swap(ret-14);
14589 break;
14590 }
14591 }
14592 while(running);
14593
14594 if(ret==8) //GO
14595 {
14596 int32_t index = *data.loaded;
14597
14598 FlashWarpSquare = -1;
14599 int32_t tm = Map.getCurrMap();
14600 int32_t ts = Map.getCurrScr();
14601 int32_t thistype = mptr->tilewarptype[index];
14602 Map.dowarp(0,index);
14603
14604 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtCAVE && thistype != wtSCROLL)
14605 {
14606 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(index*2))&3;
14607 FlashWarpClk = 32;
14608 }
14609
14610 refresh(rALL);
14611 }
14612
14613 return D_O_K;
14614 }
14615
14616 struct sw_data
14617 {
14618 int swscr[4], swtype[4], swdmap[4], wret[4];
14619 byte oflags;
14620 optional<uint> loaded;
14621
14622 sw_data(mapscr* scr) {load_scr(scr);}
14623 void load_scr(mapscr* scr)
14624 {
14625 oflags = scr->sidewarpoverlayflags;
14626 for(int q = 0; q < 4; ++q)
14627 {
14628 swscr[q] = scr->sidewarpscr[q];
14629 swtype[q] = scr->sidewarptype[q];
14630 swdmap[q] = scr->sidewarpdmap[q];
14631 wret[q] = (scr->warpreturnc >> (2*(q+4)))&3;
14632 }
14633 loaded.reset();
14634
14635 for(int32_t i=0; i<4; i++)
14636 {
14637 sidewarp_dlg[18+i].d2 = 0x80;
14638 if(scr->flags2&(1<<i))
14639 {
14640 sidewarp_dlg[18+i].flags = D_SELECTED ;
14641 sidewarp_dlg[18+i].d2 |= (scr->sidewarpindex>>(2*i))&3;
14642 }
14643 else
14644 {
14645 sidewarp_dlg[18+i].flags = 0;
14646 }
14647 }
14648 }
14649 void save_scr(mapscr* scr)
14650 {
14651 mark_save_dirty();
14652 scr->sidewarpoverlayflags = oflags;
14653 scr->warpreturnc = scr->warpreturnc & 0x00FF;
14654 for(int q = 0; q < 4; ++q)
14655 {
14656 scr->sidewarpscr[q] = swscr[q];
14657 scr->sidewarptype[q] = swtype[q];
14658 scr->sidewarpdmap[q] = swdmap[q];
14659 scr->warpreturnc |= wret[q] << (2*(q+4));
14660 }
14661
14662 scr->flags2 &= ~0xF;
14663 scr->sidewarpindex = 0;
14664 for(int32_t i=0; i<4; i++)
14665 {
14666 if(sidewarp_dlg[18+i].flags & D_SELECTED)
14667 scr->flags2 |= 1<<i;
14668 scr->sidewarpindex |= (sidewarp_dlg[18+i].d2&3) << (i*2);
14669 }
14670 }
14671
14672 void load(uint ind)
14673 {
14674 if(ind >= 4) return;
14675 loaded = ind;
14676 sidewarp_dlg[4].d1 = swtype[ind];
14677 sidewarp_dlg[5].d1 = swdmap[ind];
14678 char* buf = (char*)sidewarp_dlg[6].dp;
14679 sprintf(buf,"%02X",swscr[ind]);
14680 sidewarp_dlg[11].d1 = wret[ind];
14681 SETFLAG(sidewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
14682 for(int q = 0; q < 4; ++q)
14683 SETFLAG(sidewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
14684 }
14685 void save(uint ind)
14686 {
14687 if(ind >= 4) return;
14688 swtype[ind] = sidewarp_dlg[4].d1;
14689 swdmap[ind] = sidewarp_dlg[5].d1;
14690 char* buf = (char*)sidewarp_dlg[6].dp;
14691 swscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
14692 wret[ind] = sidewarp_dlg[11].d1;
14693 set_bit(&oflags, ind, sidewarp_dlg[12].flags & D_SELECTED);
14694 }
14695 void save()
14696 {
14697 if(loaded)
14698 save(*loaded);
14699 }
14700 void swap(uint ind)
14701 {
14702 if(ind >= 4) return;
14703 if(loaded)
14704 {
14705 save(*loaded);
14706 if(*loaded == ind)
14707 return;
14708 }
14709 load(ind);
14710 }
14711 };
14712 int32_t onSideWarp()
14713 {
14714 restore_mouse();
14715 sidewarp_dlg[0].dp=(void *) "Side Warp";
14716 sidewarp_dlg[0].dp2=get_zc_font(font_lfont);
14717
14718 mapscr* mptr = Map.CurrScr();
14719 char buf[10];
14720 sidewarp_dlg[6].dp=buf;
14721 sidewarp_dlg[13].dp = buf;
14722 sidewarp_dlg[13].dp3 = &sidewarp_dlg[5].d1;
14723
14724 vector<DIALOG*> dlgs;
14725 dlgs.push_back(&sidewarp_dlg[5]);
14726 dlgs.push_back(&sidewarp_dlg[6]);
14727 sidewarp_dlg[13].dp2 = &dlgs;
14728
14729 sw_data data(mptr);
14730 data.load(0);
14731
14732 dmap_list_size=MAXDMAPS;
14733 dmap_list_zero=true;
14734
14735 large_dialog(sidewarp_dlg);
14736
14737 bool running = true;
14738 int ret;
14739 do
14740 {
14741 ret = do_zqdialog(sidewarp_dlg,-1);
14742 switch(ret)
14743 {
14744 // OK, GO
14745 case 7: case 8:
14746 running = false;
14747 data.save();
14748 data.save_scr(mptr);
14749 refresh(rMENU);
14750 break;
14751 //Cancel
14752 case 9:
14753 running = false;
14754 break;
14755 //A,B,C,D
14756 case 14: case 15: case 16: case 17:
14757 data.swap(ret-14);
14758 break;
14759 }
14760 }
14761 while(running);
14762
14763 if(ret==8) //GO
14764 {
14765 int32_t index = *data.loaded;
14766
14767 FlashWarpSquare = -1;
14768 int32_t tm = Map.getCurrMap();
14769 int32_t ts = Map.getCurrScr();
14770
14771 int32_t thistype = mptr->sidewarptype[index];
14772 Map.dowarp(1,index);
14773
14774 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtSCROLL)
14775 {
14776 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(8+index*2))&3;
14777 FlashWarpClk = 0x20;
14778 }
14779
14780 refresh(rALL);
14781 }
14782
14783 return D_O_K;
14784 }
14785
14786
14787
14788 const char *dirlist(int32_t index, int32_t *list_size)
14789 {
14790 if(index>=0)
14791 {
14792 if(index>3)
14793 index=3;
14794
14795 return mazedirstr[index];
14796 }
14797
14798 *list_size=4;
14799 return NULL;
14800 }
14801
14802 12 static ListData path_dlg_list(dirlist, &font);
14803
14804 static const char *wipestr[] = {"None", "Circle", "Oval", "Triangle", "SMAS", "Fade Black"};
14805 // enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
14806 const char *wipelist(int32_t index, int32_t *list_size)
14807 {
14808 if(index>=0)
14809 {
14810 if(index>5)
14811 index=5;
14812
14813 return wipestr[index];
14814 }
14815
14816 *list_size=6;
14817 return NULL;
14818 }
14819
14820 12 static ListData wipe_effect_dlg_list(wipelist, &font);
14821
14822 static DIALOG path_dlg[] =
14823 {
14824 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
14825 12 { jwin_win_proc, 80, 57, 161, 182, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Maze Path", NULL, NULL },
14826 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
14827 12 { jwin_text_proc, 94, 106, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
14828 12 { jwin_text_proc, 94, 124, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
14829 12 { jwin_text_proc, 94, 142, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
14830 12 { jwin_text_proc, 94, 160, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "4th", NULL, NULL },
14831 12 { jwin_text_proc, 94, 178, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Exit", NULL, NULL },
14832 12 { jwin_text_proc, 94, 196, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Wipe effect", NULL, NULL },
14833 12 { jwin_droplist_proc, 140, 102, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
14834 12 { jwin_droplist_proc, 140, 120, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
14835 12 { jwin_droplist_proc, 140, 138, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
14836 12 { jwin_droplist_proc, 140, 156, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
14837 12 { jwin_droplist_proc, 140, 174, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
14838 12 { jwin_droplist_proc, 140, 192, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &wipe_effect_dlg_list, NULL, NULL },
14839 12 { jwin_button_proc, 90, 212, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
14840 12 { jwin_button_proc, 170, 212, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
14841 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
14842 12 { jwin_text_proc, 87, 82, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "A Lost Woods-style maze screen", NULL, NULL },
14843 12 { jwin_text_proc, 87, 92, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "with a normal and secret exit.", NULL, NULL },
14844 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
14845 };
14846
14847 int32_t onPath()
14848 {
14849 restore_mouse();
14850 path_dlg[0].dp2=get_zc_font(font_lfont);
14851
14852 for(int32_t i=0; i<4; i++)
14853 path_dlg[i+8].d1 = Map.CurrScr()->path[i];
14854
14855 path_dlg[12].d1 = Map.CurrScr()->exitdir;
14856 path_dlg[13].d1 = Map.CurrScr()->maze_transition_wipe;
14857
14858 large_dialog(path_dlg);
14859
14860 int32_t ret;
14861
14862 do
14863 {
14864 ret=do_zqdialog(path_dlg,8);
14865
14866 if(ret==14)
14867 {
14868 for(int32_t i=0; i<4; i++)
14869 {
14870 if(path_dlg[i+8].d1 == path_dlg[12].d1)
14871 {
14872 if (alert_confirm("Exit Problem","One of the path's directions is also the normal Exit direction! Continue?"))
14873 ret = -1;
14874
14875 break;
14876 }
14877 }
14878 }
14879 }
14880 while(ret == -1);
14881
14882 if(ret==14)
14883 {
14884 mark_save_dirty();
14885
14886 for(int32_t i=0; i<4; i++)
14887 Map.CurrScr()->path[i] = path_dlg[i+8].d1;
14888
14889 Map.CurrScr()->exitdir = path_dlg[12].d1;
14890 Map.CurrScr()->maze_transition_wipe = path_dlg[13].d1;
14891
14892 if(!(Map.CurrScr()->flags&fMAZE))
14893 if (alert_confirm("Screen Flag","Turn on the 'Use Maze Path' Screen Flag?\n(Go to 'Screen Data' to turn it off.)"))
14894 Map.CurrScr()->flags |= fMAZE;
14895 }
14896
14897 refresh(rMAP+rMENU);
14898 return D_O_K;
14899 }
14900
14901
14902
14903 static DIALOG editinfo_dlg[] =
14904 {
14905 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
14906 12 { jwin_win_proc, 0, 10, 208, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
14907 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
14908 12 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
14909 12 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
14910 12 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
14911 12 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
14912 12 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
14913 12 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
14914 // 8
14915 12 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
14916 12 { d_ndroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
14917 12 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
14918 12 { d_ndroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
14919 12 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
14920 12 { d_ndroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
14921 12 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
14922 12 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
14923 // 16
14924 12 { jwin_button_proc, 34, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
14925 12 { jwin_button_proc, 114, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
14926 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
14927 };
14928
14929 void EditInfoType(int32_t index)
14930 {
14931 char ps1[6],ps2[6],ps3[6];
14932 char infoname[33];
14933 char caption[40];
14934
14935 int32_t str1, str2, str3;
14936
14937 sprintf(caption,"Info Data %d",index);
14938 editinfo_dlg[0].dp = caption;
14939 editinfo_dlg[0].dp2 = get_zc_font(font_lfont);
14940
14941 sprintf(ps1,"%d",QMisc.info[index].price[0]);
14942 sprintf(ps2,"%d",QMisc.info[index].price[1]);
14943 sprintf(ps3,"%d",QMisc.info[index].price[2]);
14944 strncpy(infoname,QMisc.info[index].name,32);
14945 infoname[32] = 0;
14946 editinfo_dlg[8].dp = ps1;
14947 editinfo_dlg[10].dp = ps2;
14948 editinfo_dlg[12].dp = ps3;
14949 editinfo_dlg[15].dp = infoname;
14950 str1 = QMisc.info[index].str[0];
14951 str2 = QMisc.info[index].str[1];
14952 str3 = QMisc.info[index].str[2];
14953 editinfo_dlg[9].d1 = MsgStrings[str1].listpos;
14954 editinfo_dlg[11].d1 = MsgStrings[str2].listpos;
14955 editinfo_dlg[13].d1 = MsgStrings[str3].listpos;
14956 ListData msgs_list(msgslist2, &a4fonts[font_lfont_l]);
14957 editinfo_dlg[9].dp =
14958 editinfo_dlg[11].dp =
14959 editinfo_dlg[13].dp = (void *) &msgs_list;
14960
14961 large_dialog(editinfo_dlg);
14962
14963 int32_t ret = do_zqdialog(editinfo_dlg,-1);
14964
14965 if(ret==16)
14966 {
14967 mark_save_dirty();
14968 QMisc.info[index].price[0] = vbound(atoi(ps1), 0, 65535);
14969 QMisc.info[index].price[1] = vbound(atoi(ps2), 0, 65535);
14970 QMisc.info[index].price[2] = vbound(atoi(ps3), 0, 65535);
14971 strncpy(QMisc.info[index].name,infoname,32);
14972 str1 = editinfo_dlg[9].d1;
14973 str2 = editinfo_dlg[11].d1;
14974 str3 = editinfo_dlg[13].d1;
14975 QMisc.info[index].str[0] = msg_at_pos(str1);
14976 QMisc.info[index].str[1] = msg_at_pos(str2);
14977 QMisc.info[index].str[2] = msg_at_pos(str3);
14978
14979 //move 0s to the end
14980 word swaptmp;
14981
14982 if(QMisc.info[index].str[0] == 0)
14983 {
14984 //possibly permute the infos
14985 if(QMisc.info[index].str[1] != 0)
14986 {
14987 //swap
14988 swaptmp = QMisc.info[index].str[0];
14989 QMisc.info[index].str[0] = QMisc.info[index].str[1];
14990 QMisc.info[index].str[1] = swaptmp;
14991 swaptmp = QMisc.info[index].price[0];
14992 QMisc.info[index].price[0] = QMisc.info[index].price[1];
14993 QMisc.info[index].price[1] = swaptmp;
14994 }
14995 else if(QMisc.info[index].str[2] != 0)
14996 {
14997 //move info 0 to 1, 1 to 2, and 2 to 0
14998 swaptmp = QMisc.info[index].str[0];
14999 QMisc.info[index].str[0] = QMisc.info[index].str[2];
15000 QMisc.info[index].str[2] = QMisc.info[index].str[1];
15001 QMisc.info[index].str[1] = swaptmp;
15002 swaptmp = QMisc.info[index].price[0];
15003 QMisc.info[index].price[0] = QMisc.info[index].price[2];
15004 QMisc.info[index].price[2] = QMisc.info[index].price[1];
15005 QMisc.info[index].price[1] = swaptmp;
15006 }
15007 }
15008
15009 if(QMisc.info[index].str[1] == 0 && QMisc.info[index].str[2] != 0)
15010 //swap
15011 {
15012 swaptmp = QMisc.info[index].str[1];
15013 QMisc.info[index].str[1] = QMisc.info[index].str[2];
15014 QMisc.info[index].str[2] = swaptmp;
15015 swaptmp = QMisc.info[index].price[1];
15016 QMisc.info[index].price[1] = QMisc.info[index].price[2];
15017 QMisc.info[index].price[2] = swaptmp;
15018 }
15019 }
15020 }
15021
15022 int32_t onInfoTypes()
15023 {
15024 info_list_size = 256;
15025
15026 int32_t index = select_data("Info Types",0,infolist,"Edit","Done",get_zc_font(font_lfont));
15027
15028 while(index!=-1)
15029 {
15030 EditInfoType(index);
15031
15032 index = select_data("Info Types",index,infolist,"Edit","Done",get_zc_font(font_lfont));
15033 }
15034
15035 return D_O_K;
15036 }
15037
15038
15039
15040 //This dialogie is self-contained, and does not use dialogue control numbers in a separate array to generate its fields.
15041 static DIALOG editshop_dlg[] =
15042 {
15043 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
15044 12 { jwin_win_proc, 0, 10, 221, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15045 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15046 12 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
15047 12 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
15048 12 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
15049 12 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
15050 12 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
15051 12 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
15052 // 8
15053 12 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15054 12 { d_nidroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15055 12 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15056 12 { d_nidroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15057 12 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15058 12 { d_nidroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15059 12 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
15060 12 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
15061
15062 // 16
15063 12 { jwin_button_proc, 40, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
15064 12 { jwin_button_proc, 121, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15065 //18
15066 12 { jwin_text_proc, 130, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
15067 12 { jwin_text_proc, 130, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
15068 12 { jwin_text_proc, 130, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
15069 // 21
15070 12 { jwin_edit_proc, 155, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15071 12 { jwin_edit_proc, 155, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15072 12 { jwin_edit_proc, 155, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15073
15074 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15075 };
15076
15077 void EditShopType(int32_t index)
15078 {
15079
15080 build_bii_list(true);
15081 char ps1[6],ps2[6],ps3[6];
15082 char info1[6],info2[6],info3[6];
15083 char shopname[32];
15084 char caption[40];
15085
15086 sprintf(caption,"Shop Data %d",index);
15087 editshop_dlg[0].dp = caption;
15088 editshop_dlg[0].dp2=get_zc_font(font_lfont);
15089
15090 sprintf(ps1,"%d",QMisc.shop[index].price[0]);
15091 sprintf(ps2,"%d",QMisc.shop[index].price[1]);
15092 sprintf(ps3,"%d",QMisc.shop[index].price[2]);
15093
15094 sprintf(info1,"%d",QMisc.shop[index].str[0]);
15095 sprintf(info2,"%d",QMisc.shop[index].str[1]);
15096 sprintf(info3,"%d",QMisc.shop[index].str[2]);
15097
15098 sprintf(shopname,"%s",QMisc.shop[index].name);
15099 editshop_dlg[8].dp = ps1;
15100 editshop_dlg[10].dp = ps2;
15101 editshop_dlg[12].dp = ps3;
15102 editshop_dlg[15].dp = shopname;
15103
15104 editshop_dlg[21].dp = info1;
15105 editshop_dlg[22].dp = info2;
15106 editshop_dlg[23].dp = info3;
15107
15108 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
15109
15110 editshop_dlg[9].dp = (void *) &item_list;
15111 editshop_dlg[11].dp = (void *) &item_list;
15112 editshop_dlg[13].dp = (void *) &item_list;
15113
15114 for(int32_t i=0; i<3; ++i)
15115 {
15116 if(QMisc.shop[index].hasitem[i])
15117 {
15118 for(int32_t j=0; j<bii_cnt; j++)
15119 {
15120 if(bii[j].i == QMisc.shop[index].item[i])
15121 {
15122 editshop_dlg[9+(i<<1)].d1 = j;
15123 }
15124 }
15125 }
15126 else
15127 {
15128 editshop_dlg[9+(i<<1)].d1 = -2;
15129 }
15130 }
15131
15132 large_dialog(editshop_dlg);
15133
15134 int32_t ret = do_zqdialog(editshop_dlg,-1);
15135
15136 if(ret==16)
15137 {
15138 mark_save_dirty();
15139 QMisc.shop[index].price[0] = vbound(atoi(ps1), 0, 65535);
15140 QMisc.shop[index].price[1] = vbound(atoi(ps2), 0, 65535);
15141 QMisc.shop[index].price[2] = vbound(atoi(ps3), 0, 65535);
15142
15143 QMisc.shop[index].str[0] = vbound(atoi(info1), 0, 65535);
15144 QMisc.shop[index].str[1] = vbound(atoi(info2), 0, 65535);
15145 QMisc.shop[index].str[2] = vbound(atoi(info3), 0, 65535);
15146
15147 snprintf(QMisc.shop[index].name, 32, "%s",shopname);
15148
15149 for(int32_t i=0; i<3; ++i)
15150 {
15151 if(bii[editshop_dlg[9+(i<<1)].d1].i == -2)
15152 {
15153 QMisc.shop[index].hasitem[i] = 0;
15154 QMisc.shop[index].item[i] = 0;
15155 QMisc.shop[index].price[i] = 0;
15156 }
15157 else
15158 {
15159 QMisc.shop[index].hasitem[i] = 1;
15160 QMisc.shop[index].item[i] = bii[editshop_dlg[9+(i<<1)].d1].i;
15161 }
15162 }
15163
15164 //filter all the 0 items to the end (yeah, bubble sort; sue me)
15165 word swaptmp;
15166
15167 for(int32_t j=0; j<3-1; j++)
15168 {
15169 for(int32_t k=0; k<2-j; k++)
15170 {
15171 if(QMisc.shop[index].hasitem[k]==0)
15172 {
15173 swaptmp = QMisc.shop[index].item[k];
15174 QMisc.shop[index].item[k] = QMisc.shop[index].item[k+1];
15175 QMisc.shop[index].item[k+1] = swaptmp;
15176 swaptmp = QMisc.shop[index].price[k];
15177 QMisc.shop[index].price[k] = QMisc.shop[index].price[k+1];
15178 QMisc.shop[index].price[k+1] = swaptmp;
15179 swaptmp = QMisc.shop[index].hasitem[k];
15180 QMisc.shop[index].hasitem[k] = QMisc.shop[index].item[k+1];
15181 QMisc.shop[index].hasitem[k+1] = swaptmp;
15182 }
15183 }
15184 }
15185 }
15186 }
15187
15188 int32_t onShopTypes()
15189 {
15190 shop_list_size = 256;
15191
15192 int32_t index = select_data("Shop Types",0,shoplist,"Edit","Done",get_zc_font(font_lfont));
15193
15194 while(index!=-1)
15195 {
15196 EditShopType(index);
15197 index = select_data("Shop Types",index,shoplist,"Edit","Done",get_zc_font(font_lfont));
15198 }
15199
15200 return D_O_K;
15201 }
15202
15203 void call_bottle_dlg(int32_t index);
15204 int32_t onBottleTypes()
15205 {
15206 bottle_list_size = 64;
15207 int32_t index = 0;
15208
15209 while(index > -1)
15210 {
15211 index = select_data("Bottle Types", index, bottlelist, "Edit", "Done", get_zc_font(font_lfont));
15212 if(index > -1)
15213 call_bottle_dlg(index);
15214 }
15215
15216 return D_O_K;
15217 }
15218
15219 void call_bottleshop_dlg(int32_t index);
15220 int32_t onBottleShopTypes()
15221 {
15222 bottleshop_list_size = 256;
15223 int32_t index = 0;
15224
15225 while(index > -1)
15226 {
15227 index = select_data("Bottle Shop Types", index, bottleshoplist, "Edit", "Done", get_zc_font(font_lfont));
15228 if(index > -1)
15229 call_bottleshop_dlg(index);
15230 }
15231
15232 return D_O_K;
15233 }
15234
15235 int32_t onSaveMenus()
15236 {
15237 SaveMenuListerDialog().show();
15238 return D_O_K;
15239 }
15240
15241
15242 static char item_drop_set_str_buf[70];
15243 int32_t item_drop_set_list_size=MAXITEMDROPSETS;
15244
15245 const char *itemdropsetlist(int32_t index, int32_t *list_size)
15246 {
15247 if(index>=0)
15248 {
15249 bound(index,0,item_drop_set_list_size-1);
15250 sprintf(item_drop_set_str_buf,"%3d: %s",index,item_drop_sets[index].name);
15251 return item_drop_set_str_buf;
15252 }
15253
15254 *list_size=item_drop_set_list_size;
15255 return NULL;
15256 }
15257
15258 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c);
15259
15260 static int32_t edititemdropset_1_list[] =
15261 {
15262 // dialog control number
15263 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,24,25,26,27,28, -1
15264 };
15265
15266 static int32_t edititemdropset_2_list[] =
15267 {
15268 // dialog control number
15269 12, 13, 29, 30, 31, 32, 33,34,35,36,37,38,39,40,41,42,43, -1
15270 };
15271
15272 static TABPANEL edititemdropset_tabs[] =
15273 {
15274 // (text)
15275 { (char *)" Page 1 ", D_SELECTED, edititemdropset_1_list, 0, NULL },
15276 { (char *)" Page 2 ", 0, edititemdropset_2_list, 0, NULL },
15277 { NULL, 0, NULL, 0, NULL }
15278 };
15279
15280 static DIALOG edititemdropset_dlg[] =
15281 {
15282 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
15283 12 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15284 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15285
15286 // 2
15287 12 { jwin_button_proc, 89, 213, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
15288 12 { jwin_button_proc, 169, 213, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15289
15290 // 4
15291 12 { jwin_text_proc, 9, 29, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
15292 12 { jwin_edit_proc, 39, 25, 275, 16, vc(12), vc(1), 0, 0, 32, 0, NULL, NULL, NULL },
15293 12 { jwin_text_proc, 9, 47, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Nothing Chance:", NULL, NULL },
15294 12 { d_itemdropedit_proc, 84, 43, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15295
15296 12 { jwin_tab_proc, 4, 65, 312, 143, vc(0), vc(15), 0, 0, 0, 0, (void *) edititemdropset_tabs, NULL, (void *)edititemdropset_dlg },
15297 12 { jwin_text_proc, 114, 43+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15298 // 10
15299 12 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
15300 12 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
15301 12 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
15302 12 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
15303
15304 // 14
15305 12 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15306 12 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15307 12 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15308 12 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15309 12 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15310 12 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15311 12 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15312 12 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15313 12 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15314 12 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15315 12 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15316 12 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15317 12 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15318 12 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15319 12 { jwin_text_proc, 37, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15320 // 29
15321 12 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15322 12 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15323 12 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15324 12 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15325 12 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15326 12 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15327 12 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15328 12 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15329 12 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15330 12 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15331 12 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15332 12 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15333 12 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15334 12 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
15335 12 { jwin_text_proc, 39, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15336 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15337 };
15338
15339 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c)
15340 {
15341 int32_t ret = jwin_edit_proc(msg,d,c);
15342
15343 if(msg==MSG_DRAW)
15344 {
15345 int32_t t = atoi((char*)edititemdropset_dlg[7].dp);
15346
15347 for(int32_t i=0; i<10; ++i)
15348 {
15349 t += atoi((char*)edititemdropset_dlg[14+(i*3)].dp);
15350 }
15351
15352 {
15353 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[7].dp) / zc_max(t,1));
15354 sprintf((char*)edititemdropset_dlg[9].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
15355 object_message(&edititemdropset_dlg[9],MSG_DRAW,c);
15356 }
15357
15358 for(int32_t i=0; i<10; ++i)
15359 {
15360 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[14+(i*3)].dp) / zc_max(t,1));
15361 sprintf((char*)edititemdropset_dlg[16+(i*3)].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
15362 object_message(&edititemdropset_dlg[16+(i*3)],MSG_DRAW,c);
15363 }
15364
15365 }
15366
15367 return ret;
15368 }
15369
15370 void EditItemDropSet(int32_t index)
15371 {
15372 build_bii_list(true);
15373 char chance[11][10];
15374 char itemdropsetname[64];
15375 char caption[40];
15376 char percent_str[11][5];
15377
15378 sprintf(caption,"Item Drop Set Data %d",index);
15379 edititemdropset_dlg[0].dp = caption;
15380 edititemdropset_dlg[0].dp2=get_zc_font(font_lfont);
15381
15382 sprintf(itemdropsetname,"%s",item_drop_sets[index].name);
15383 edititemdropset_dlg[5].dp = itemdropsetname;
15384
15385 sprintf(chance[0],"%d",item_drop_sets[index].chance[0]);
15386 edititemdropset_dlg[7].dp = chance[0];
15387
15388 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
15389 sprintf(percent_str[0]," ");
15390 edititemdropset_dlg[9].dp = percent_str[0];
15391
15392 for(int32_t i=0; i<10; ++i)
15393 {
15394 sprintf(chance[i+1],"%d",item_drop_sets[index].chance[i+1]);
15395 edititemdropset_dlg[14+(i*3)].dp = chance[i+1];
15396 edititemdropset_dlg[15+(i*3)].dp = (void *) &item_list;
15397 sprintf(percent_str[i+1]," ");
15398 edititemdropset_dlg[16+(i*3)].dp = percent_str[i+1];
15399
15400 if(item_drop_sets[index].chance[i+1]==0)
15401 {
15402 edititemdropset_dlg[15+(i*3)].d1 = -2;
15403 }
15404 else
15405 {
15406 for(int32_t j=0; j<bii_cnt; j++)
15407 {
15408 if(bii[j].i == item_drop_sets[index].item[i])
15409 {
15410 edititemdropset_dlg[15+(i*3)].d1 = j;
15411 }
15412 }
15413 }
15414 }
15415
15416 large_dialog(edititemdropset_dlg);
15417
15418 int32_t ret = do_zqdialog(edititemdropset_dlg,-1);
15419
15420 if(ret==2)
15421 {
15422 mark_save_dirty();
15423
15424 sprintf(item_drop_sets[index].name,"%s",itemdropsetname);
15425
15426 item_drop_sets[index].chance[0]=atoi(chance[0]);
15427
15428 for(int32_t i=0; i<10; ++i)
15429 {
15430 item_drop_sets[index].chance[i+1]=atoi(chance[i+1]);
15431
15432 if(bii[edititemdropset_dlg[15+(i*3)].d1].i == -2)
15433 {
15434 item_drop_sets[index].chance[i+1]=0;
15435 }
15436 else
15437 {
15438 item_drop_sets[index].item[i] = bii[edititemdropset_dlg[15+(i*3)].d1].i;
15439 }
15440
15441 if(item_drop_sets[index].chance[i+1]==0)
15442 {
15443 item_drop_sets[index].item[i] = 0;
15444 }
15445 }
15446 }
15447 }
15448
15449 9 int32_t count_item_drop_sets()
15450 {
15451 9 int32_t count=0;
15452 9 bool found=false;
15453
15454
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2195 times.
2195 for(count=255; (count>0); --count)
15455 {
15456
2/2
✓ Branch 0 taken 2186 times.
✓ Branch 1 taken 24056 times.
26242 for(int32_t i=0; (i<11); ++i)
15457 {
15458
2/2
✓ Branch 0 taken 24047 times.
✓ Branch 1 taken 9 times.
24056 if(item_drop_sets[count].chance[i]!=0)
15459 {
15460 9 found=true;
15461 9 break;
15462 }
15463 24047 }
15464
15465
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2186 times.
2195 if(found)
15466 {
15467 9 break;
15468 }
15469 2186 }
15470
15471 9 return count+1;
15472 }
15473
15474 int32_t onItemDropSets()
15475 {
15476 item_drop_set_list_size = MAXITEMDROPSETS;
15477
15478 int32_t index = select_data("Item Drop Sets",0,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
15479
15480 while(index!=-1)
15481 {
15482 EditItemDropSet(index);
15483 index = select_data("Item Drop Sets",index,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
15484 }
15485
15486 return D_O_K;
15487 }
15488
15489 int32_t curr_ring = 0;
15490
15491 void EditWarpRingScr(int32_t ring,int32_t index)
15492 {
15493 char caption[40],buf[10];
15494 restore_mouse();
15495
15496 sprintf(caption,"Ring %d Warp %d",ring,index+1);
15497 warpring_warp_dlg[0].dp = (void *)caption;
15498 warpring_warp_dlg[0].dp2=get_zc_font(font_lfont);
15499
15500 sprintf(buf,"%02X",QMisc.warp[ring].scr[index]);
15501 warpring_warp_dlg[3].d1 = QMisc.warp[ring].dmap[index];
15502 warpring_warp_dlg[4].dp = buf;
15503 warpring_warp_dlg[8].dp = buf;
15504 warpring_warp_dlg[8].dp3 = &warpring_warp_dlg[3].d1;
15505
15506 vector<DIALOG*> dlgs;
15507 dlgs.push_back(&warpring_warp_dlg[3]);
15508 dlgs.push_back(&warpring_warp_dlg[4]);
15509 warpring_warp_dlg[8].dp2 = &dlgs;
15510
15511 dmap_list_size=MAXDMAPS;
15512 dmap_list_zero=true;
15513
15514 large_dialog(warpring_warp_dlg);
15515
15516 int32_t ret=do_zqdialog(warpring_warp_dlg,-1);
15517
15518 if(ret==5 || ret==6)
15519 {
15520 mark_save_dirty();
15521 QMisc.warp[ring].dmap[index] = warpring_warp_dlg[3].d1;
15522 QMisc.warp[ring].scr[index] = zc_xtoi(buf);
15523 }
15524
15525 if(ret==6)
15526 {
15527 Map.dowarp2(ring,index);
15528 refresh(rALL);
15529 }
15530 }
15531
15532 int32_t d_warplist_proc(int32_t msg,DIALOG *d,int32_t c)
15533 {
15534 if(msg==MSG_DRAW)
15535 {
15536 int32_t *xy = (int32_t*)(d->dp3);
15537 int32_t ring = curr_ring;
15538 int32_t dmap = QMisc.warp[ring].dmap[d->d1];
15539 float temp_scale = 1.5;
15540
15541 drawdmap(dmap);
15542
15543 if(xy[0]||xy[1])
15544 {
15545 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
15546 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
15547 int32_t w = 84;
15548 int32_t h = 52;
15549 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
15550 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
15551 }
15552
15553 if(xy[2]||xy[3])
15554 {
15555 textprintf_ex(screen,font,d->x+int32_t(xy[2]*temp_scale),d->y+int32_t(xy[3]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %d ",DMaps[dmap].map+1);
15556 }
15557
15558 if(xy[4]||xy[5])
15559 {
15560 textprintf_ex(screen,font,d->x+int32_t(xy[4]*temp_scale),d->y+int32_t(xy[5]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level:%2d ",DMaps[dmap].level);
15561 }
15562
15563 if(xy[6]||xy[7])
15564 {
15565 textprintf_ex(screen,font,d->x+int32_t(xy[6]*temp_scale),d->y+int32_t(xy[7]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Scr: 0x%02X ",QMisc.warp[ring].scr[d->d1]);
15566 }
15567 }
15568
15569 return jwin_list_proc(msg,d,c);
15570 }
15571
15572 int32_t d_wclist_proc(int32_t msg,DIALOG *d,int32_t c)
15573 {
15574 int32_t d1 = d->d1;
15575 int32_t ret = jwin_droplist_proc(msg,d,c);
15576 QMisc.warp[curr_ring].size=d->d1+3;
15577
15578 if(d->d1 != d1)
15579 return D_CLOSE;
15580
15581 return ret;
15582 }
15583
15584 const char *wclist(int32_t index, int32_t *list_size)
15585 {
15586 static char buf[2];
15587
15588 if(index>=0)
15589 {
15590 if(index>6)
15591 index=6;
15592
15593 sprintf(buf,"%d",index+3);
15594 return buf;
15595 }
15596
15597 *list_size=7;
15598 return NULL;
15599 }
15600
15601 //int32_t warpringdmapxy[8] = {160,116,160,90,160,102,160,154};
15602 int32_t warpringdmapxy[8] = {80,26,80,0,80,12,80,78};
15603
15604 12 static ListData number_list(numberlist, &font);
15605 12 static ListData wc_list(wclist, &font);
15606
15607 static DIALOG warpring_dlg[] =
15608 {
15609 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
15610 12 { jwin_win_proc, 0, 0, 193, 166, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15611 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15612 12 { jwin_text_proc, 16, 33, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Count:", NULL, NULL },
15613 12 { d_wclist_proc, 72, 29, 48, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 1, 0, (void *) &wc_list, NULL, NULL },
15614 // 4
15615 12 { d_warplist_proc, 16, 50, 65, 71, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &number_list, NULL, warpringdmapxy },
15616 12 { jwin_button_proc, 26, 140, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
15617 12 { jwin_button_proc, 106, 140, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
15618 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
15619 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15620 };
15621
15622 int32_t select_warp()
15623 {
15624 QMisc.warp[curr_ring].size = vbound(QMisc.warp[curr_ring].size,3,9);
15625 number_list_zero = false;
15626
15627 int32_t ret=4;
15628
15629 large_dialog(warpring_dlg);
15630
15631 do
15632 {
15633 number_list_size = QMisc.warp[curr_ring].size;
15634 warpring_dlg[3].d1 = QMisc.warp[curr_ring].size-3;
15635 ret = do_zqdialog(warpring_dlg,ret);
15636 }
15637 while(ret==3);
15638
15639 if(ret==6 || ret==0)
15640 {
15641 return -1;
15642 }
15643
15644 return warpring_dlg[4].d1;
15645 }
15646
15647 void EditWarpRing(int32_t ring)
15648 {
15649 char buf[40];
15650 sprintf(buf,"Ring %d Warps",ring);
15651 warpring_dlg[0].dp = buf;
15652 warpring_dlg[0].dp2 = get_zc_font(font_lfont);
15653 curr_ring = ring;
15654
15655 int32_t index = select_warp();
15656
15657 while(index!=-1)
15658 {
15659 EditWarpRingScr(ring,index);
15660 index = select_warp();
15661 }
15662 }
15663
15664 int32_t onWarpRings()
15665 {
15666 number_list_size = 9;
15667 number_list_zero = true;
15668
15669 int32_t index = select_data("Warp Rings",0,numberlist,"Edit","Done",get_zc_font(font_lfont));
15670
15671 while(index!=-1)
15672 {
15673 EditWarpRing(index);
15674 number_list_size = 9;
15675 number_list_zero = true;
15676 index = select_data("Warp Rings",index,numberlist,"Edit","Done",get_zc_font(font_lfont));
15677 }
15678
15679 return D_O_K;
15680 }
15681
15682 enemy_struct bie[eMAXGUYS];
15683 enemy_struct ce[100];
15684 int32_t enemy_type=0,bie_cnt=-1,ce_cnt;
15685
15686 //Uses old_max_guys[] in zq_misc.cpp to define what are visible if bool hide is set true. -Z
15687 void build_bie_list(bool hide)
15688 {
15689 bie[0].s = (char *)"(None)";
15690 bie[0].i = 0;
15691 bie_cnt=1;
15692
15693 for(int32_t i=1; i<eMAXGUYS; i++)
15694 {
15695 if (i < eSTART) continue; // ignore guys - enemies only!
15696
15697 if(i >= OLDMAXGUYS || old_guy_string[i][strlen(old_guy_string[i])-1]!=' ' || !hide)
15698 {
15699 bie[bie_cnt].s = (char *)guy_string[i];
15700 bie[bie_cnt].i = i;
15701 ++bie_cnt;
15702 }
15703 }
15704
15705 for(int32_t i=1; i<bie_cnt-1; i++) //Start at 1 so '(None)' isn't alphabetized!
15706 {
15707 for(int32_t j=i+1; j<bie_cnt; j++)
15708 {
15709 if(strcmp(bie[i].s,bie[j].s)>0)
15710 {
15711 zc_swap(bie[i],bie[j]);
15712 }
15713 }
15714 }
15715 }
15716
15717 int32_t efrontfacingtile(int32_t id)
15718 {
15719 int32_t anim = get_qr(qr_NEWENEMYTILES)?guysbuf[id].e_anim:guysbuf[id].anim;
15720 int32_t usetile = 0;
15721
15722 switch(anim)
15723 {
15724
15725 case aNONE: break;
15726 case aAQUA:
15727 if(!(get_qr(qr_NEWENEMYTILES) && guysbuf[id].attributes[0]))
15728 break;
15729
15730 case aWALLM:
15731 case aGHOMA:
15732 usetile=1;
15733 break;
15734
15735 //Fallthrough
15736 case a2FRM4DIR:
15737 case aWALK:
15738 usetile=2;
15739 break;
15740
15741 case aLEV:
15742 case a3FRM4DIR:
15743 usetile=3;
15744 break;
15745
15746 case aLANM:
15747 usetile = !(get_qr(qr_NEWENEMYTILES))?0:4;
15748 break;
15749
15750 case aNEWDONGO:
15751 case a4FRM8EYE:
15752 case aNEWWIZZ:
15753 case aARMOS4:
15754 case aNEWTEK:
15755 case aNEWWALLM:
15756 case a4FRM4DIRF:
15757 case a4FRM4DIR:
15758 case a4FRM8DIRF:
15759 case a4FRMPOS8DIR:
15760 case a4FRMPOS8DIRF:
15761 case a4FRMPOS4DIR:
15762 case a4FRMPOS4DIRF:
15763 usetile=4;
15764 break;
15765
15766 case aDONGO:
15767 usetile=6;
15768 break;
15769
15770 case aDONGOBS:
15771 usetile=24;
15772 break;
15773
15774 case aNEWLEV:
15775 usetile=40;
15776 break;
15777
15778 case aNEWZORA:
15779 if(guysbuf[id].type==eeZORA)
15780 usetile=44;
15781
15782 break;
15783
15784 case aGLEEOK:
15785 if(!get_qr(qr_NEWENEMYTILES))
15786 usetile = (guysbuf[id].s_tile - guysbuf[id].tile)+1;
15787 else
15788 usetile = (guysbuf[id].attributes[7]);
15789
15790 break;
15791 }
15792
15793 return zc_max(get_qr(qr_NEWENEMYTILES) ? -guysbuf[id].e_tile
15794 : -guysbuf[id].tile, usetile);
15795 }
15796
15797 int32_t onEnemies()
15798 {
15799 call_screenenemies_dialog();
15800 refresh(rALL);
15801 return D_O_K;
15802 }
15803
15804 int32_t onHeader()
15805 {
15806 call_header_dlg();
15807 return D_O_K;
15808 }
15809
15810 void call_cheats_dlg();
15811 int32_t onCheats()
15812 {
15813 call_cheats_dlg();
15814 return D_O_K;
15815 }
15816
15817 bool do_x_button(BITMAP *dest, int32_t x, int32_t y)
15818 {
15819 bool over=false;
15820
15821 while(gui_mouse_b())
15822 {
15823 custom_vsync();
15824
15825 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
15826 {
15827 if(!over)
15828 {
15829 draw_x_button(dest, x, y, D_SELECTED);
15830 over=true;
15831 }
15832 }
15833 else
15834 {
15835 if(over)
15836 {
15837 draw_x_button(dest, x, y, 0);
15838 over=false;
15839 }
15840 }
15841 }
15842
15843 return over;
15844 }
15845
15846 bool do_question_button(BITMAP *dest, int32_t x, int32_t y)
15847 {
15848 bool over=false;
15849
15850 while(gui_mouse_b())
15851 {
15852 custom_vsync();
15853
15854 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
15855 {
15856 if(!over)
15857 {
15858 draw_question_button(dest, x, y, D_SELECTED);
15859 over=true;
15860 }
15861 }
15862 else
15863 {
15864 if(over)
15865 {
15866 draw_question_button(dest, x, y, 0);
15867 over=false;
15868 }
15869 }
15870 }
15871
15872 return over;
15873 }
15874
15875
15876 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
15877 {
15878 return D_O_K;
15879 }
15880
15881 static int32_t last_combo=0;
15882 static int32_t last_cset=0;
15883
3/4
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 98292 times.
✓ Branch 3 taken 12 times.
98304 static combo_alias temp_aliases[MAXCOMBOALIASES];
15884
15885 extern int32_t scheme[jcMAX];
15886
15887 int32_t d_comboa_proc(int32_t msg,DIALOG *d,int32_t c)
15888 {
15889 //these are here to bypass compiler warnings about unused arguments
15890 c=c;
15891
15892 combo_alias *combo;
15893 combo = &temp_aliases[comboa_cnt];
15894 int32_t position;
15895 int32_t cur_layer, temp_layer;
15896 int32_t lay_count=0;
15897 int32_t size = 2;
15898
15899 int32_t cx1=(gui_mouse_x()-d->x-(120-(combo->width*8)));
15900 int32_t cy1=(gui_mouse_y()-d->y-(80-(combo->height*8)));
15901 int32_t cx=cx1/(16*size);
15902 int32_t cy=cy1/(16*size);
15903
15904 int32_t co,cs;
15905
15906
15907 switch(msg)
15908 {
15909 case MSG_CLICK:
15910 if((cx>combo->width)||(cx1<0))
15911 return D_O_K;
15912
15913 if((cy>combo->height)||(cy1<0))
15914 return D_O_K;
15915
15916 for(int32_t j=0; j<layer_cnt; j++)
15917 {
15918 if(combo->layermask&(1<<j))
15919 lay_count++;
15920 }
15921
15922 position=(lay_count)*(combo->width+1)*(combo->height+1);
15923 position+=(cy*(combo->width+1))+cx;
15924
15925 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
15926 {
15927 combo->combos[position] = 0;
15928 combo->csets[position] = 0;
15929
15930 while(gui_mouse_b())
15931 {
15932 /* do nothing */
15933 rest(1);
15934 }
15935
15936 return D_REDRAW;
15937 }
15938
15939 co=combo->combos[position];
15940 cs=combo->csets[position];
15941
15942 if((co==0)||(key[KEY_ZC_LCONTROL]))
15943 {
15944 co=last_combo;
15945 cs=last_cset;
15946 }
15947
15948 if((select_combo_2(co,cs)))
15949 {
15950 last_combo = co;
15951 last_cset = cs;
15952
15953 combo->combos[position]=co;
15954 combo->csets[position]=cs;
15955 }
15956
15957 return D_REDRAW;
15958 break;
15959
15960 case MSG_DRAW:
15961 BITMAP *buf = create_bitmap_ex(8,d->w,d->h);
15962
15963 if(buf)
15964 {
15965 clear_bitmap(buf);
15966
15967 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
15968 {
15969 int32_t k=0;
15970 cur_layer=0;
15971 temp_layer=combo->layermask;
15972
15973 while((temp_layer!=0)&&(k<z))
15974 {
15975 if(temp_layer&1)
15976 {
15977 k++;
15978 }
15979
15980 cur_layer++;
15981 temp_layer = temp_layer>>1;
15982 }
15983
15984 for(int32_t y=0; (y<d->h)&&((y/16)<=combo->height); y+=16)
15985 {
15986 for(int32_t x=0; (x<d->w)&&((x/16)<=combo->width); x+=16)
15987 {
15988 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y/16)*(combo->width+1))+(x/16));
15989
15990 if(combo->combos[cpos])
15991 {
15992 if(!((d-1)->flags&D_SELECTED)||(cur_layer==layer_cnt))
15993 {
15994 if(z==0)
15995 {
15996 puttile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
15997 }
15998 else
15999 {
16000 overtile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
16001 }
16002 }
16003 }
16004 }
16005 }
16006 }
16007
16008 rectfill(screen, d->x-2,d->y-2,d->x+256+2,d->y+176+2,jwin_pal[jcBOX]);
16009 int32_t dx = 120-(combo->width*8)+d->x;
16010 int32_t dy = 80-(combo->height*8)+d->y;
16011 stretch_blit(buf,screen,0,0,(combo->width+1)*16,(combo->height+1)*16,dx,dy,(combo->width+1)*16*size,(combo->height+1)*16*size);
16012 //blit(buf,screen,0,0,120-(combo->width*8)+d->x,80-(combo->height*8)+d->y,(combo->width+1)*16,(combo->height+1)*16);
16013 (d-11)->w = (combo->width+1)*16*size+2;
16014 (d-11)->h = (combo->height+1)*16*size+2;
16015 (d-11)->x = 120-(combo->width*8)+4*size+2+(d-14)->x;
16016 (d-11)->y = 80-(combo->height*8)+25*size+2+(d-14)->y;
16017 object_message((d-11),MSG_DRAW,0);
16018
16019 destroy_bitmap(buf);
16020 }
16021
16022 break;
16023 }
16024
16025 return D_O_K;
16026 }
16027
16028 void draw_combo_alias_thumbnail(BITMAP *dest, combo_alias const* combo, int32_t x, int32_t y, int32_t size)
16029 {
16030 if(!combo->combo)
16031 {
16032 int32_t cur_layer, temp_layer;
16033
16034 int32_t cw=combo->width+1;
16035 int32_t ch=combo->height+1;
16036 int32_t dw=cw<<4;
16037 int32_t dh=ch<<4;
16038 int32_t sw=16, sh=16, sx=0, sy=0;
16039
16040 if(cw<ch)
16041 {
16042 sw=((cw<<4)/ch);
16043 sx=((16-sw)>>1);
16044 }
16045 else
16046 {
16047 sh=((ch<<4)/cw);
16048 sy=((16-sh)>>1);
16049 }
16050
16051 BITMAP *buf = create_bitmap_ex(8,dw,dh);
16052 BITMAP *buf2 = create_bitmap_ex(8, 16*size, 16*size);
16053 clear_bitmap(buf);
16054 clear_bitmap(buf2);
16055
16056 if(buf&&(combo->width>0||combo->height>0||combo->combos[0]>0))
16057 {
16058 clear_bitmap(buf);
16059
16060 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
16061 {
16062 int32_t k=0;
16063 cur_layer=0;
16064 temp_layer=combo->layermask;
16065
16066 while((temp_layer!=0)&&(k<z))
16067 {
16068 if(temp_layer&1)
16069 {
16070 k++;
16071 }
16072
16073 cur_layer++;
16074 temp_layer = temp_layer>>1;
16075 }
16076
16077 for(int32_t y2=0; (y2<dh)&&((y2>>4)<=combo->height); y2+=16)
16078 {
16079 for(int32_t x2=0; (x2<dw)&&((x2>>4)<=combo->width); x2+=16)
16080 {
16081 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y2/16)*(combo->width+1))+(x2/16));
16082
16083 if(combo->combos[cpos])
16084 {
16085 if(z==0)
16086 {
16087 puttile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
16088 }
16089 else
16090 {
16091 overtile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
16092 }
16093 }
16094 }
16095 }
16096 }
16097
16098 stretch_blit(buf, buf2, 0, 0, (cw*16), (ch*16), sx*size, sy*size, sw*size, sh*size);
16099 blit(buf2, dest, 0, 0, x, y, 16*size, 16*size);
16100 }
16101 else
16102 {
16103 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
16104 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
16105 }
16106
16107 if(buf)
16108 destroy_bitmap(buf);
16109
16110 if(buf2)
16111 destroy_bitmap(buf2);
16112 }
16113 else
16114 {
16115 if(combobuf[combo->combo].tile>0)
16116 {
16117 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
16118 put_combo(dest, x, y, combo->combo, combo->cset, 0, 0, size);
16119 }
16120 else
16121 {
16122 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
16123 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
16124 }
16125 }
16126 }
16127
16128 int32_t d_comboat_proc(int32_t msg,DIALOG *d,int32_t)
16129 {
16130 switch(msg)
16131 {
16132 case MSG_CLICK:
16133 {
16134 int32_t c2;
16135 int32_t cs;
16136 c2=temp_aliases[comboa_cnt].combo;
16137 cs=temp_aliases[comboa_cnt].cset;
16138
16139 if(gui_mouse_b()&2) //right mouse button
16140 {
16141 if(c2==0&&cs==0&&!(gui_mouse_b()&1))
16142 {
16143 return D_O_K;
16144 }
16145
16146 temp_aliases[comboa_cnt].combo=0;
16147 temp_aliases[comboa_cnt].cset=0;
16148 }
16149
16150 if(gui_mouse_b()&1) //left mouse button
16151 {
16152 if(select_combo_2(c2, cs))
16153 {
16154 temp_aliases[comboa_cnt].combo=c2;
16155 temp_aliases[comboa_cnt].cset=cs;
16156 }
16157
16158 return D_REDRAW;
16159 }
16160 else
16161 {
16162 return D_REDRAWME;
16163 }
16164 }
16165 break;
16166
16167 case MSG_DRAW:
16168 draw_combo_alias_thumbnail(screen, &temp_aliases[comboa_cnt], d->x-1, d->y-1,2);
16169 break;
16170
16171 default:
16172 break;
16173 }
16174
16175 return D_O_K;
16176 }
16177
16178 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c);
16179
16180 static DIALOG orgcomboa_dlg[] =
16181 {
16182 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
16183 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Organize Combo Aliases", NULL, NULL },
16184 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
16185 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16186
16187 { jwin_radio_proc, 10, 40, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Copy", NULL, NULL },
16188 { jwin_text_proc, 10, 50, 33, 9, 0, 0, 0, 0, 0, 0, (void *) "", NULL, NULL },
16189 // { jwin_radio_proc, 10, 50, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Move", NULL, NULL },
16190 { jwin_radio_proc, 10, 60, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Swap", NULL, NULL },
16191 /* 6 */ { jwin_edit_proc, 110, 35, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
16192 { jwin_edit_proc, 110, 55, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
16193 { jwin_text_proc, 60, 40, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Source", NULL, NULL },
16194 { jwin_text_proc, 60, 60, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Dest", NULL, NULL},
16195 { jwin_radio_proc, 10, 80, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Insert new (before source)", NULL, NULL },
16196 { jwin_radio_proc, 10, 100, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Delete source", NULL, NULL },
16197 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16198 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16199 };
16200
16201 static DIALOG newcomboa_dlg[] =
16202 {
16203 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
16204 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Properties", NULL, NULL },
16205 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
16206 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16207 { jwin_text_proc, 24, 34, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Width", NULL, NULL },
16208 { jwin_text_proc, 24, 52, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Height", NULL, NULL },
16209 { jwin_text_proc, 24, 70, 100, 8, 0, 0, 0, 0, 0, 0, (void *) "Layers to Draw On:", NULL, NULL },
16210 { jwin_edit_proc, 104, 30, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
16211 { jwin_edit_proc, 122, 48, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
16212 { jwin_check_proc, 24, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "1", NULL, NULL },
16213 { jwin_check_proc, 50, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "2", NULL, NULL },
16214 { jwin_check_proc, 76, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "3", NULL, NULL },
16215 { jwin_check_proc, 102, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "4", NULL, NULL },
16216 { jwin_check_proc, 128, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "5", NULL, NULL },
16217 { jwin_check_proc, 154, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "6", NULL, NULL },
16218
16219
16220 // { jwin_text_proc, 24, 106, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Copy to :", NULL, NULL },
16221 //15
16222 // { jwin_edit_proc, 100, 100, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
16223 // { jwin_check_proc, 84, 106, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "", NULL, NULL },
16224
16225 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16226 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16227 };
16228
16229 bool swapComboAlias(int32_t source, int32_t dest)
16230 {
16231 if(source==dest)
16232 return false;
16233 zc_swap(temp_aliases[source],temp_aliases[dest]);
16234 return true;
16235 }
16236
16237
16238 bool copyComboAlias(int32_t source, int32_t dest)
16239 {
16240 if(source == dest)
16241 return false;
16242 temp_aliases[dest] = temp_aliases[source];
16243 return true;
16244 }
16245
16246 int32_t getcurrentcomboalias();
16247
16248 int32_t onOrgComboAliases()
16249 {
16250 char cSrc[8];
16251 char cDest[8];
16252 sprintf(cSrc,"%d", getcurrentcomboalias());
16253 strcpy(cDest,cSrc);
16254 int32_t iSrc = 0;
16255 int32_t iDest = 0;
16256
16257 //sprintf(cSrc,"0");
16258 //sprintf(cDest,"0");
16259 orgcomboa_dlg[0].dp2=get_zc_font(font_lfont);
16260 orgcomboa_dlg[6].dp= cSrc;
16261 orgcomboa_dlg[7].dp= cDest;
16262 int32_t ret = 1;
16263 large_dialog(orgcomboa_dlg);
16264 do
16265 {
16266 iSrc = atoi((char*)orgcomboa_dlg[6].dp);
16267 iDest = atoi((char*)orgcomboa_dlg[7].dp);
16268 ret = do_zqdialog(orgcomboa_dlg,-1);
16269
16270 if(ret!=1) return ret;
16271
16272 if((atoi((char*) orgcomboa_dlg[6].dp))<0 || (atoi((char*) orgcomboa_dlg[6].dp)) > MAXCOMBOALIASES-1)
16273 {
16274 displayinfo("Error",fmt::format("Invalid source (range 0-{})", MAXCOMBOALIASES-1));
16275 ret = 1;
16276 }
16277
16278 // 10,11=ins, del
16279 if(orgcomboa_dlg[10].flags & D_SELECTED) //insert
16280 {
16281 for(int32_t j=MAXCOMBOALIASES-1; j>(atoi((char*) orgcomboa_dlg[6].dp)); --j)
16282 copyComboAlias(j-1,j);
16283 ret = -1;
16284 }
16285
16286 if(orgcomboa_dlg[11].flags & D_SELECTED) //delete
16287 {
16288 for(int32_t j=(atoi((char*) orgcomboa_dlg[6].dp)); j<MAXCOMBOALIASES-1; ++j)
16289 copyComboAlias(j+1,j);
16290 ret = -1;
16291 }
16292
16293 if((atoi((char*) orgcomboa_dlg[6].dp)) == (atoi((char*) orgcomboa_dlg[7].dp)))
16294 {
16295 displayinfo("Error","Source and dest can't be the same.");
16296 ret = 1;
16297 }
16298
16299 if((atoi((char*) orgcomboa_dlg[7].dp)) < 0 || (atoi((char*) orgcomboa_dlg[7].dp)) > MAXCOMBOALIASES-1)
16300 {
16301 displayinfo("Error",fmt::format("Invalid dest (range 0-{})", MAXCOMBOALIASES-1));
16302 ret = 1;
16303 }
16304
16305 if(orgcomboa_dlg[3].flags & D_SELECTED) //copy
16306 {
16307 copyComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
16308 ret = -1;
16309 }
16310
16311 if(orgcomboa_dlg[5].flags & D_SELECTED) //swap
16312 {
16313 swapComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
16314 ret = -1;
16315 }
16316 }
16317 while(ret==1);
16318 return ret;
16319 }
16320
16321 int32_t onNewComboAlias()
16322 {
16323 combo_alias *combo;
16324 combo = &temp_aliases[comboa_cnt];
16325
16326 char cwidth[5];
16327 char cheight[5];
16328 // char cp[3];
16329
16330 word temp_combos[16*11*7];
16331 byte temp_csets[16*11*7];
16332 sprintf(cwidth, "%d", combo->width+1);
16333 sprintf(cheight, "%d", combo->height+1);
16334 int32_t old_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
16335 int32_t old_width=combo->width;
16336 int32_t old_height=combo->height;
16337 int32_t oldlayer=combo->layermask;
16338
16339 for(int32_t i=0; i<old_count; i++)
16340 {
16341 temp_csets[i] = combo->csets[i];
16342 temp_combos[i] = combo->combos[i];
16343 }
16344
16345 newcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
16346 newcomboa_dlg[6].dp = cwidth;
16347 newcomboa_dlg[7].dp = cheight;
16348 newcomboa_dlg[8].flags = (combo->layermask&1)? D_SELECTED : 0;
16349 newcomboa_dlg[9].flags = (combo->layermask&2)? D_SELECTED : 0;
16350 newcomboa_dlg[10].flags = (combo->layermask&4)? D_SELECTED : 0;
16351 newcomboa_dlg[11].flags = (combo->layermask&8)? D_SELECTED : 0;
16352 newcomboa_dlg[12].flags = (combo->layermask&16)? D_SELECTED : 0;
16353 newcomboa_dlg[13].flags = (combo->layermask&32)? D_SELECTED : 0;
16354
16355 large_dialog(newcomboa_dlg);
16356
16357 int32_t ret = do_zqdialog(newcomboa_dlg,-1);
16358
16359 if(ret==1)
16360 {
16361 combo->width = ((atoi(cwidth)-1)<16)?zc_max(0,(atoi(cwidth)-1)):15;
16362 combo->height = ((atoi(cheight)-1)<11)?zc_max(0,(atoi(cheight)-1)):10;
16363 combo->layermask=0;
16364 combo->layermask |= (newcomboa_dlg[8].flags&D_SELECTED)?1:0;
16365 combo->layermask |= (newcomboa_dlg[9].flags&D_SELECTED)?2:0;
16366 combo->layermask |= (newcomboa_dlg[10].flags&D_SELECTED)?4:0;
16367 combo->layermask |= (newcomboa_dlg[11].flags&D_SELECTED)?8:0;
16368 combo->layermask |= (newcomboa_dlg[12].flags&D_SELECTED)?16:0;
16369 combo->layermask |= (newcomboa_dlg[13].flags&D_SELECTED)?32:0;
16370
16371 int32_t new_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
16372
16373 combo->combos.clear();
16374 combo->csets.clear();
16375
16376 int32_t j=1;
16377 int32_t old_size=(old_width+1)*(old_height+1);
16378 int32_t new_start[7] =
16379 {
16380 0,
16381 ((combo->width+1)*(combo->height+1)*(1)),
16382 ((combo->width+1)*(combo->height+1)*(2)),
16383 ((combo->width+1)*(combo->height+1)*(3)),
16384 ((combo->width+1)*(combo->height+1)*(4)),
16385 ((combo->width+1)*(combo->height+1)*(5)),
16386 ((combo->width+1)*(combo->height+1)*(6))
16387 };
16388 int32_t new_layers[6] = {0,0,0,0,0,0};
16389 int32_t temp_layer = combo->layermask;
16390 int32_t temp_old = oldlayer;
16391 int32_t old_layers[6] = {0,0,0,0,0,0};
16392 int32_t k=1;
16393
16394 for(int32_t i=0; (i<6)&&(temp_layer!=0); j++,temp_layer>>=1,temp_old>>=1)
16395 {
16396 if(temp_layer&1)
16397 {
16398 new_layers[i] = j;
16399 //if(oldlayer&(1<<(j-1))) old_layers[i] = k++;
16400 i++;
16401 }
16402
16403 if(temp_old&1)
16404 {
16405 if(temp_layer&1)
16406 {
16407 old_layers[i-1] = k;
16408 }
16409
16410 k++;
16411 }
16412 }
16413
16414 for(int32_t i=0; i<new_count; i++)
16415 {
16416 if(i>=new_start[6])
16417 {
16418 //oldl=oldlayer>>(new_layers[5]-1);
16419 j=i-new_start[6];
16420
16421 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[5]-1))))
16422 {
16423 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
16424 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
16425 }
16426 else
16427 {
16428 combo->combos[i] = 0;
16429 combo->csets[i] = 0;
16430 }
16431 }
16432 else if(i>=new_start[5])
16433 {
16434 //oldl=oldlayer>>(new_layers[4]-1);
16435 j=i-new_start[5];
16436
16437 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[4]-1))))
16438 {
16439 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
16440 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
16441 }
16442 else
16443 {
16444 combo->combos[i] = 0;
16445 combo->csets[i] = 0;
16446 }
16447 }
16448 else if(i>=new_start[4])
16449 {
16450 //oldl=oldlayer>>(new_layers[3]-1);
16451 j=i-new_start[4];
16452
16453 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[3]-1))))
16454 {
16455 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
16456 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
16457 }
16458 else
16459 {
16460 combo->combos[i] = 0;
16461 combo->csets[i] = 0;
16462 }
16463 }
16464 else if(i>=new_start[3])
16465 {
16466 //oldl=oldlayer>>(new_layers[2]-1);
16467 j=i-new_start[3];
16468
16469 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[2]-1))))
16470 {
16471 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
16472 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
16473 }
16474 else
16475 {
16476 combo->combos[i] = 0;
16477 combo->csets[i] = 0;
16478 }
16479 }
16480 else if(i>=new_start[2])
16481 {
16482 //oldl=oldlayer>>(new_layers[1]-1);
16483 j=i-new_start[2];
16484
16485 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[1]-1))))
16486 {
16487 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
16488 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
16489 }
16490 else
16491 {
16492 combo->combos[i] = 0;
16493 combo->csets[i] = 0;
16494 }
16495 }
16496 else if(i>=new_start[1])
16497 {
16498 //oldl=oldlayer>>(new_layers[0]-1);
16499 j=i-new_start[1];
16500
16501 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[0]-1))))
16502 {
16503 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
16504 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
16505 }
16506 else
16507 {
16508 combo->combos[i] = 0;
16509 combo->csets[i] = 0;
16510 }
16511 }
16512 else if(i>=new_start[0])
16513 {
16514 if(((i/(combo->width+1))<=old_height)&&((i%(combo->width+1))<=old_width))
16515 {
16516 combo->combos[i] = temp_combos[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
16517 combo->csets[i] = temp_csets[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
16518 }
16519 else
16520 {
16521 combo->combos[i] = 0;
16522 combo->csets[i] = 0;
16523 }
16524 }
16525 }
16526
16527 set_comboaradio(combo->layermask);
16528 }
16529
16530 return ret;
16531 }
16532
16533 int32_t d_orgcomboa_proc(int32_t msg, DIALOG *d, int32_t c)
16534 {
16535 //these are here to bypass compiler warnings about unused arguments
16536 c=c;
16537
16538 int32_t down=0;
16539 int32_t selected=(d->flags&D_SELECTED)?1:0;
16540 int32_t last_draw;
16541
16542 switch(msg)
16543 {
16544
16545 case MSG_DRAW:
16546 {
16547 FONT *tfont=font;
16548 font=get_zc_font(font_lfont_l);
16549 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
16550 font=tfont;
16551 }
16552 break;
16553
16554 case MSG_WANTFOCUS:
16555 return D_WANTFOCUS;
16556
16557 case MSG_KEY:
16558 /* close dialog? */
16559 onOrgComboAliases();
16560 return D_REDRAW;
16561
16562 /* or just toggle */
16563 /*d->flags ^= D_SELECTED;
16564 object_message(d, MSG_DRAW, 0);
16565 break;*/
16566
16567 case MSG_CLICK:
16568 last_draw = 0;
16569
16570 /* track the mouse until it is released */
16571 while(gui_mouse_b())
16572 {
16573 down = mouse_in_rect(d->x, d->y, d->w, d->h);
16574
16575 /* redraw? */
16576 if(last_draw != down)
16577 {
16578 if(down != selected)
16579 d->flags |= D_SELECTED;
16580 else
16581 d->flags &= ~D_SELECTED;
16582
16583 object_message(d, MSG_DRAW, 0);
16584 last_draw = down;
16585 }
16586
16587 /* let other objects continue to animate */
16588 broadcast_dialog_message(MSG_IDLE, 0);
16589 }
16590
16591 /* redraw in normal state */
16592 if(down)
16593 {
16594 if(d->flags&D_EXIT)
16595 {
16596 d->flags &= ~D_SELECTED;
16597 object_message(d, MSG_DRAW, 0);
16598 }
16599 }
16600
16601 /* should we close the dialog? */
16602 if(down)
16603 {
16604 onOrgComboAliases();
16605 return D_REDRAW;
16606 }
16607
16608 break;
16609 }
16610
16611 return D_O_K;
16612 }
16613
16614 int32_t d_comboabutton_proc(int32_t msg, DIALOG *d, int32_t c)
16615 {
16616 //these are here to bypass compiler warnings about unused arguments
16617 c=c;
16618
16619 int32_t down=0;
16620 int32_t selected=(d->flags&D_SELECTED)?1:0;
16621 int32_t last_draw;
16622
16623 switch(msg)
16624 {
16625
16626 case MSG_DRAW:
16627 {
16628 FONT *tfont=font;
16629 font=get_zc_font(font_lfont_l);
16630 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
16631 font=tfont;
16632 }
16633 break;
16634
16635 case MSG_WANTFOCUS:
16636 return D_WANTFOCUS;
16637
16638 case MSG_KEY:
16639 /* close dialog? */
16640 onNewComboAlias();
16641 return D_REDRAW;
16642
16643 /* or just toggle */
16644 /*d->flags ^= D_SELECTED;
16645 object_message(d, MSG_DRAW, 0);
16646 break;*/
16647
16648 case MSG_CLICK:
16649 last_draw = 0;
16650
16651 /* track the mouse until it is released */
16652 while(gui_mouse_b())
16653 {
16654 down = mouse_in_rect(d->x, d->y, d->w, d->h);
16655
16656 /* redraw? */
16657 if(last_draw != down)
16658 {
16659 if(down != selected)
16660 d->flags |= D_SELECTED;
16661 else
16662 d->flags &= ~D_SELECTED;
16663
16664 object_message(d, MSG_DRAW, 0);
16665 last_draw = down;
16666 }
16667
16668 /* let other objects continue to animate */
16669 broadcast_dialog_message(MSG_IDLE, 0);
16670 }
16671
16672 /* redraw in normal state */
16673 if(down)
16674 {
16675 if(d->flags&D_EXIT)
16676 {
16677 d->flags &= ~D_SELECTED;
16678 object_message(d, MSG_DRAW, 0);
16679 }
16680 }
16681
16682 /* should we close the dialog? */
16683 if(down)
16684 {
16685 onNewComboAlias();
16686 return D_REDRAW;
16687 }
16688
16689 break;
16690 }
16691
16692 return D_O_K;
16693 }
16694
16695 int32_t d_comboacheck_proc(int32_t msg, DIALOG *d, int32_t c)
16696 {
16697 int32_t temp = d->flags&D_SELECTED;
16698 int32_t ret=jwin_checkfont_proc(msg,d,c);
16699
16700 if(temp != (d->flags&D_SELECTED))
16701 {
16702 return D_REDRAW;
16703 }
16704
16705 return ret;
16706 }
16707
16708 static DIALOG editcomboa_dlg[] =
16709 {
16710 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
16711 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Edit", NULL, NULL },
16712 { jwin_button_proc, 148, 212, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
16713 { jwin_button_proc, 232, 212, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16714 { jwin_frame_proc, 4+121, 28+81, 1, 1, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
16715 { d_comboabutton_proc, 25, 212, 81, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Properties", NULL, NULL },
16716 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16717 { d_comboa_radio_proc, 285, 44, 30, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "0", NULL, NULL },
16718 { d_comboa_radio_proc, 285, 54, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
16719 { d_comboa_radio_proc, 285, 64, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "2", NULL, NULL },
16720 { d_comboa_radio_proc, 285, 74, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "3", NULL, NULL },
16721 { d_comboa_radio_proc, 285, 84, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "4", NULL, NULL },
16722
16723 { d_comboa_radio_proc, 285, 94, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "5", NULL, NULL },
16724 { d_comboa_radio_proc, 285, 104, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "6", NULL, NULL },
16725 { d_comboacheck_proc, 285, 164, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
16726 { d_comboa_proc, 6, 27, 256, 176, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16727 { jwin_ctext_proc, 290, 176, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Only Show", NULL, NULL },
16728 { jwin_ctext_proc, 290, 186, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Current", NULL, NULL },
16729 { jwin_ctext_proc, 290, 196, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Layer", NULL, NULL },
16730 { jwin_ctext_proc, 290, 122, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Thumbnail", NULL, NULL },
16731 { jwin_frame_proc, 280, 132, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
16732 { d_comboat_proc, 282, 134, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16733
16734 //21
16735 { d_orgcomboa_proc, 106, 212, 21, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Org", NULL, NULL },
16736 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16737 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16738 };
16739
16740 int32_t getcurrentcomboalias()
16741 {
16742 return editcomboa_dlg[5].d1;
16743 }
16744
16745 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c)
16746 {
16747 int32_t temp = layer_cnt;
16748 int32_t ret = jwin_radiofont_proc(msg,d,c);
16749
16750 if(editcomboa_dlg[6].flags&D_SELECTED) layer_cnt=0;
16751 else if(editcomboa_dlg[7].flags&D_SELECTED) layer_cnt=1;
16752 else if(editcomboa_dlg[8].flags&D_SELECTED) layer_cnt=2;
16753 else if(editcomboa_dlg[9].flags&D_SELECTED) layer_cnt=3;
16754 else if(editcomboa_dlg[10].flags&D_SELECTED) layer_cnt=4;
16755 else if(editcomboa_dlg[11].flags&D_SELECTED) layer_cnt=5;
16756 else if(editcomboa_dlg[12].flags&D_SELECTED) layer_cnt=6;
16757
16758 if(temp != layer_cnt)
16759 {
16760 return D_REDRAW;
16761 }
16762
16763 return ret;
16764 }
16765
16766 int32_t set_comboaradio(byte layermask)
16767 {
16768 if(editcomboa_dlg[7].flags&D_SELECTED) editcomboa_dlg[7].flags &= ~D_SELECTED;
16769
16770 if(editcomboa_dlg[8].flags&D_SELECTED) editcomboa_dlg[8].flags &= ~D_SELECTED;
16771
16772 if(editcomboa_dlg[9].flags&D_SELECTED) editcomboa_dlg[9].flags &= ~D_SELECTED;
16773
16774 if(editcomboa_dlg[10].flags&D_SELECTED) editcomboa_dlg[10].flags &= ~D_SELECTED;
16775
16776 if(editcomboa_dlg[11].flags&D_SELECTED) editcomboa_dlg[11].flags &= ~D_SELECTED;
16777
16778 if(editcomboa_dlg[12].flags&D_SELECTED) editcomboa_dlg[12].flags &= ~D_SELECTED;
16779
16780 if(!(layermask&1)) editcomboa_dlg[7].flags |= D_DISABLED;
16781 else editcomboa_dlg[7].flags &= ~D_DISABLED;
16782
16783 if(!(layermask&2)) editcomboa_dlg[8].flags |= D_DISABLED;
16784 else editcomboa_dlg[8].flags &= ~D_DISABLED;
16785
16786 if(!(layermask&4)) editcomboa_dlg[9].flags |= D_DISABLED;
16787 else editcomboa_dlg[9].flags &= ~D_DISABLED;
16788
16789 if(!(layermask&8)) editcomboa_dlg[10].flags |= D_DISABLED;
16790 else editcomboa_dlg[10].flags &= ~D_DISABLED;
16791
16792 if(!(layermask&16)) editcomboa_dlg[11].flags |= D_DISABLED;
16793 else editcomboa_dlg[11].flags &= ~D_DISABLED;
16794
16795 if(!(layermask&32)) editcomboa_dlg[12].flags |= D_DISABLED;
16796 else editcomboa_dlg[12].flags &= ~D_DISABLED;
16797
16798 editcomboa_dlg[6].flags |= D_SELECTED;
16799 layer_cnt=0;
16800 return 1;
16801 }
16802
16803 int32_t onEditComboPool()
16804 {
16805 call_cpool_dlg(combo_pool_pos);
16806 return D_O_K;
16807 }
16808 int32_t onEditAutoCombo()
16809 {
16810 call_autocombo_dlg(combo_auto_pos);
16811 return D_O_K;
16812 }
16813 int32_t onEditComboAlias()
16814 {
16815 comboa_cnt = combo_apos;
16816 reset_combo_animations();
16817 reset_combo_animations2();
16818
16819 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
16820 temp_aliases[i] = combo_aliases[i];
16821
16822 editcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
16823 set_comboaradio(temp_aliases[comboa_cnt].layermask);
16824 editcomboa_dlg[5].d1 = comboa_cnt;
16825
16826 bool small_d1 = editcomboa_dlg[0].d1==0;
16827 large_dialog(editcomboa_dlg,2);
16828
16829 if(small_d1)
16830 {
16831 for(int32_t i=6; i<=12; i++)
16832 {
16833 editcomboa_dlg[i].w=30*1.5;
16834 editcomboa_dlg[i].h=9*1.5;
16835 }
16836
16837 editcomboa_dlg[13].w=17*1.5;
16838 editcomboa_dlg[13].h=9*1.5;
16839 editcomboa_dlg[4].w=81*1.5;
16840 editcomboa_dlg[4].h=21*1.5;
16841 editcomboa_dlg[4].dp2=get_zc_font(font_lfont_l);
16842 editcomboa_dlg[21].w=21*1.5;
16843 editcomboa_dlg[21].h=21*1.5;
16844 editcomboa_dlg[21].dp2=get_zc_font(font_lfont_l);
16845 }
16846
16847 int32_t ret=do_zqdialog(editcomboa_dlg,-1);
16848
16849 if(ret==1)
16850 {
16851 mark_save_dirty();
16852
16853 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
16854 combo_aliases[i] = temp_aliases[i];
16855 }
16856
16857 setup_combo_animations();
16858 setup_combo_animations2();
16859 return D_O_K;
16860 }
16861 void call_calias_dlg(int index)
16862 {
16863 combo_apos = comboa_cnt = index;
16864 onEditComboAlias();
16865 }
16866
16867 int32_t onSelectFFCombo()
16868 {
16869 FFCListerDialog().show();
16870 return D_O_K;
16871 }
16872
16873 static int32_t as_ffc_list[] = { 4, 5, 6, -1};
16874 static int32_t as_global_list[] = { 7, 8, 9, -1}; //Why does putting 15 in here not place my message only on the global tab? ~Joe
16875 static int32_t as_item_list[] = { 10, 11, 12, -1};
16876 static int32_t as_npc_list[] = { 18, 19, 20, -1}; //npc scripts TAB
16877 static int32_t as_lweapon_list[] = { 21, 22, 23, -1}; //lweapon scripts TAB
16878 static int32_t as_eweapon_list[] = { 24, 25, 26, -1}; //eweapon scripts TAB
16879 static int32_t as_hero_list[] = { 27, 28, 29, -1}; //hero scripts TAB
16880 static int32_t as_screen_list[] = { 30, 31, 32, -1}; //screendata scripts TAB
16881 static int32_t as_dmap_list[] = { 33, 34, 35, -1}; //dmapdata scripts TAB
16882 static int32_t as_itemsprite_list[] = { 36, 37, 38, -1}; //dmapdata scripts TAB
16883 static int32_t as_comboscript_list[] = { 39, 40, 41, -1}; //combodata scripts TAB
16884 static int32_t as_genericscript_list[] = { 45, 46, 47, -1}; //generic scripts TAB
16885 static int32_t as_subscreenscript_list[] = { 48, 49, 50, -1}; //generic scripts TAB
16886
16887 static TABPANEL assignscript_tabs[] =
16888 {
16889 // (text)
16890 { (char *)"FFC", D_SELECTED, as_ffc_list, 0, NULL },
16891 { (char *)"Global", 0, as_global_list, 0, NULL },
16892 { (char *)"Item", 0, as_item_list, 0, NULL },
16893 { (char *)"NPC", 0, as_npc_list, 0, NULL },
16894 { (char *)"LWeapon", 0, as_lweapon_list, 0, NULL },
16895 { (char *)"EWeapon", 0, as_eweapon_list, 0, NULL },
16896 { (char *)"Hero", 0, as_hero_list, 0, NULL },
16897 { (char *)"DMap", 0, as_dmap_list, 0, NULL },
16898 { (char *)"Screen", 0, as_screen_list, 0, NULL },
16899 { (char *)"Item Sprite", 0, as_itemsprite_list, 0, NULL },
16900 { (char *)"Combo", 0, as_comboscript_list, 0, NULL },
16901 { (char *)"Generic", 0, as_genericscript_list, 0, NULL },
16902 { (char *)"Subscreen", 0, as_subscreenscript_list, 0, NULL },
16903 { NULL, 0, NULL, 0, NULL }
16904 };
16905
16906 const char *assignffclist(int32_t index, int32_t *list_size)
16907 {
16908 if(index<0)
16909 {
16910 *list_size = (int32_t)ffcmap.size();
16911 return NULL;
16912 }
16913
16914 return ffcmap[index].output.c_str();
16915 }
16916
16917 const char *assigngloballist(int32_t index, int32_t *list_size)
16918 {
16919 if(index<0)
16920 {
16921 *list_size = (int32_t)globalmap.size();
16922 return NULL;
16923 }
16924
16925 return globalmap[index].output.c_str();
16926 }
16927
16928 const char *assigncombolist(int32_t index, int32_t *list_size)
16929 {
16930 if(index<0)
16931 {
16932 *list_size = (int32_t)comboscriptmap.size();
16933 return NULL;
16934 }
16935
16936 return comboscriptmap[index].output.c_str();
16937 }
16938
16939 const char *assigngenericlist(int32_t index, int32_t *list_size)
16940 {
16941 if(index<0)
16942 {
16943 *list_size = ((int32_t)genericmap.size());
16944 return NULL;
16945 }
16946
16947 return genericmap[index].output.c_str();
16948 }
16949
16950 const char *assignsubscreenlist(int32_t index, int32_t *list_size)
16951 {
16952 if(index<0)
16953 {
16954 *list_size = ((int32_t)subscreenmap.size());
16955 return NULL;
16956 }
16957
16958 return subscreenmap[index].output.c_str();
16959 }
16960
16961 const char *assignitemlist(int32_t index, int32_t *list_size)
16962 {
16963 if(index<0)
16964 {
16965 *list_size = (int32_t)itemmap.size();
16966 return NULL;
16967 }
16968
16969 return itemmap[index].output.c_str();
16970 }
16971 const char *assignnpclist(int32_t index, int32_t *list_size)
16972 {
16973 if(index<0)
16974 {
16975 *list_size = (int32_t)npcmap.size();
16976 return NULL;
16977 }
16978
16979 return npcmap[index].output.c_str();
16980 }
16981
16982 const char *assignlweaponlist(int32_t index, int32_t *list_size)
16983 {
16984 if(index<0)
16985 {
16986 *list_size = (int32_t)lwpnmap.size();
16987 return NULL;
16988 }
16989
16990 return lwpnmap[index].output.c_str();
16991 }
16992
16993 const char *assigneweaponlist(int32_t index, int32_t *list_size)
16994 {
16995 if(index<0)
16996 {
16997 *list_size = (int32_t)ewpnmap.size();
16998 return NULL;
16999 }
17000
17001 return ewpnmap[index].output.c_str();
17002 }
17003
17004 const char *assignplayerlist(int32_t index, int32_t *list_size)
17005 {
17006 if(index<0)
17007 {
17008 *list_size = (int32_t)playermap.size();
17009 return NULL;
17010 }
17011
17012 return playermap[index].output.c_str();
17013 }
17014
17015 const char *assigndmaplist(int32_t index, int32_t *list_size)
17016 {
17017 if(index<0)
17018 {
17019 *list_size = (int32_t)dmapmap.size();
17020 return NULL;
17021 }
17022
17023 return dmapmap[index].output.c_str();
17024 }
17025
17026 const char *assignscreenlist(int32_t index, int32_t *list_size)
17027 {
17028 if(index<0)
17029 {
17030 *list_size = (int32_t)screenmap.size();
17031 return NULL;
17032 }
17033
17034 return screenmap[index].output.c_str();
17035 }
17036
17037 const char *assignitemspritelist(int32_t index, int32_t *list_size)
17038 {
17039 if(index<0)
17040 {
17041 *list_size = (int32_t)itemspritemap.size();
17042 return NULL;
17043 }
17044
17045 return itemspritemap[index].output.c_str();
17046 }
17047
17048 const char *assignffcscriptlist(int32_t index, int32_t *list_size)
17049 {
17050 if(index<0)
17051 {
17052 *list_size = (int32_t)asffcscripts.size();
17053 return NULL;
17054 }
17055
17056 return asffcscripts[index].c_str();
17057 }
17058
17059 const char *assignglobalscriptlist(int32_t index, int32_t *list_size)
17060 {
17061 if(index<0)
17062 {
17063 *list_size = (int32_t)asglobalscripts.size();
17064 return NULL;
17065 }
17066
17067 return asglobalscripts[index].c_str();
17068 }
17069
17070 const char *assignitemscriptlist(int32_t index, int32_t *list_size)
17071 {
17072 if(index<0)
17073 {
17074 *list_size = (int32_t)asitemscripts.size();
17075 return NULL;
17076 }
17077
17078 return asitemscripts[index].c_str();
17079 }
17080
17081 const char *assignnpcscriptlist(int32_t index, int32_t *list_size)
17082 {
17083 if(index<0)
17084 {
17085 *list_size = (int32_t)asnpcscripts.size();
17086 return NULL;
17087 }
17088
17089 return asnpcscripts[index].c_str();
17090 }
17091
17092 const char *assignlweaponscriptlist(int32_t index, int32_t *list_size)
17093 {
17094 if(index<0)
17095 {
17096 *list_size = (int32_t)aslweaponscripts.size();
17097 return NULL;
17098 }
17099
17100 return aslweaponscripts[index].c_str();
17101 }
17102
17103 const char *assigneweaponscriptlist(int32_t index, int32_t *list_size)
17104 {
17105 if(index<0)
17106 {
17107 *list_size = (int32_t)aseweaponscripts.size();
17108 return NULL;
17109 }
17110
17111 return aseweaponscripts[index].c_str();
17112 }
17113
17114 const char *assignplayerscriptlist(int32_t index, int32_t *list_size)
17115 {
17116 if(index<0)
17117 {
17118 *list_size = (int32_t)asplayerscripts.size();
17119 return NULL;
17120 }
17121
17122 return asplayerscripts[index].c_str();
17123 }
17124
17125 const char *assigndmapscriptlist(int32_t index, int32_t *list_size)
17126 {
17127 if(index<0)
17128 {
17129 *list_size = (int32_t)asdmapscripts.size();
17130 return NULL;
17131 }
17132
17133 return asdmapscripts[index].c_str();
17134 }
17135
17136 const char *assignscreenscriptlist(int32_t index, int32_t *list_size)
17137 {
17138 if(index<0)
17139 {
17140 *list_size = (int32_t)asscreenscripts.size();
17141 return NULL;
17142 }
17143
17144 return asscreenscripts[index].c_str();
17145 }
17146
17147 const char *assignitemspritescriptlist(int32_t index, int32_t *list_size)
17148 {
17149 if(index<0)
17150 {
17151 *list_size = (int32_t)asitemspritescripts.size();
17152 return NULL;
17153 }
17154
17155 return asitemspritescripts[index].c_str();
17156 }
17157
17158 const char *assigncomboscriptlist(int32_t index, int32_t *list_size)
17159 {
17160 if(index<0)
17161 {
17162 *list_size = (int32_t)ascomboscripts.size();
17163 return NULL;
17164 }
17165
17166 return ascomboscripts[index].c_str();
17167 }
17168
17169 const char *assigngenericscriptlist(int32_t index, int32_t *list_size)
17170 {
17171 if(index<0)
17172 {
17173 *list_size = (int32_t)asgenericscripts.size();
17174 return NULL;
17175 }
17176
17177 return asgenericscripts[index].c_str();
17178 }
17179
17180 const char *assignsubscreenscriptlist(int32_t index, int32_t *list_size)
17181 {
17182 if(index<0)
17183 {
17184 *list_size = (int32_t)assubscreenscripts.size();
17185 return NULL;
17186 }
17187
17188 return assubscreenscripts[index].c_str();
17189 }
17190
17191 12 static ListData assignffc_list(assignffclist, &font);
17192 12 static ListData assignffcscript_list(assignffcscriptlist, &font);
17193 12 static ListData assignglobal_list(assigngloballist, &font);
17194 12 static ListData assignglobalscript_list(assignglobalscriptlist, &font);
17195 12 static ListData assignitem_list(assignitemlist, &font);
17196 12 static ListData assignitemscript_list(assignitemscriptlist, &font);
17197 12 static ListData assignnpc_list(assignnpclist, &font);
17198 12 static ListData assignnpcscript_list(assignnpcscriptlist, &font);
17199 12 static ListData assignlweapon_list(assignlweaponlist, &font);
17200 12 static ListData assignlweaponscript_list(assignlweaponscriptlist, &font);
17201 12 static ListData assigneweapon_list(assigneweaponlist, &font);
17202 12 static ListData assigneweaponscript_list(assigneweaponscriptlist, &font);
17203
17204 12 static ListData assignplayer_list(assignplayerlist, &font);
17205 12 static ListData assignplayerscript_list(assignplayerscriptlist, &font);
17206
17207 12 static ListData assigndmap_list(assigndmaplist, &font);
17208 12 static ListData assigndmapscript_list(assigndmapscriptlist, &font);
17209
17210 12 static ListData assignscreen_list(assignscreenlist, &font);
17211 12 static ListData assignscreenscript_list(assignscreenscriptlist, &font);
17212
17213 12 static ListData assignitemsprite_list(assignitemspritelist, &font);
17214 12 static ListData assignitemspritescript_list(assignitemspritescriptlist, &font);
17215
17216 12 static ListData assigncombo_list(assigncombolist, &font);
17217 12 static ListData assigncomboscript_list(assigncomboscriptlist, &font);
17218
17219 12 static ListData assigngeneric_list(assigngenericlist, &font);
17220 12 static ListData assigngenericscript_list(assigngenericscriptlist, &font);
17221
17222 12 static ListData assignsubscreen_list(assignsubscreenlist, &font);
17223 12 static ListData assignsubscreenscript_list(assignsubscreenscriptlist, &font);
17224
17225 static DIALOG assignscript_dlg[] =
17226 {
17227 // x y w h fg bg key flags d1 d2 dp
17228 12 { jwin_win_proc, 0, 0, 330, 236, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Assign Compiled Script", NULL, NULL },
17229 12 { jwin_tab_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, (void*)assignscript_dlg },
17230 12 { jwin_button_proc, 251, 207, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
17231 12 { jwin_button_proc, 182, 207, 61, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
17232 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffc_list, NULL, NULL },
17233 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffcscript_list, NULL, NULL },
17234 //6
17235 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17236 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobal_list, NULL, NULL },
17237 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobalscript_list, NULL, NULL },
17238 //9
17239 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17240 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitem_list, NULL, NULL },
17241 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemscript_list, NULL, NULL },
17242 //12
17243 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17244 //13
17245 12 { jwin_check_proc, 22, 211, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Output ZASM code to allegro.log", NULL, NULL },
17246 12 { jwin_text_proc, 22, 178, 90, 24, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
17247 12 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
17248 //16
17249 12 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
17250 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17251 //npc scripts
17252 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpc_list, NULL, NULL },
17253 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpcscript_list, NULL, NULL },
17254 //20
17255 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17256 //21
17257 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweapon_list, NULL, NULL },
17258 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweaponscript_list, NULL, NULL },
17259 //23
17260 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17261 //24
17262 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweapon_list, NULL, NULL },
17263 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweaponscript_list, NULL, NULL },
17264 //26
17265 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17266 //27
17267 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayer_list, NULL, NULL },
17268 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayerscript_list, NULL, NULL },
17269 //29
17270 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17271 //30
17272 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreen_list, NULL, NULL },
17273 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreenscript_list, NULL, NULL },
17274 //32
17275 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17276 //33
17277 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmap_list, NULL, NULL },
17278 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmapscript_list, NULL, NULL },
17279 //35
17280 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17281 //36
17282 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemsprite_list, NULL, NULL },
17283 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemspritescript_list, NULL, NULL },
17284 //38
17285 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17286
17287 //39
17288 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncombo_list, NULL, NULL },
17289 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncomboscript_list, NULL, NULL },
17290 //41
17291 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17292 12 { jwin_button_proc, 78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
17293 12 { jwin_button_proc, 174+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
17294 12 { jwin_button_proc, 87+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear", NULL, NULL },
17295 //45
17296 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngeneric_list, NULL, NULL },
17297 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngenericscript_list, NULL, NULL },
17298 //47
17299 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17300 //48
17301 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreen_list, NULL, NULL },
17302 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreenscript_list, NULL, NULL },
17303 //50
17304 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
17305 12 { jwin_check_proc, 22, 221, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "...And output ZASM comments", NULL, NULL },
17306
17307 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17308
17309 };
17310
17311 int32_t txtout(BITMAP* dest, const char* txt, int32_t x, int32_t y, bool disabled)
17312 {
17313 if(disabled)
17314 {
17315 gui_textout_ln(dest, font, (uint8_t*)txt, x+1, y+1, scheme[jcLIGHT], scheme[jcBOX], 0);
17316 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcMEDDARK], -1, 0);
17317 }
17318 else
17319 {
17320 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcBOXFG], scheme[jcBOX], 0);
17321 }
17322 }
17323
17324 int32_t jwin_zmeta_proc(int32_t msg, DIALOG *d, int32_t )
17325 {
17326 int32_t ret = D_O_K;
17327 ASSERT(d);
17328
17329 BITMAP* target = (msg==MSG_START ? NULL : screen);
17330 switch(msg)
17331 {
17332 case MSG_START:
17333 case MSG_DRAW:
17334 {
17335 FONT *oldfont = font;
17336
17337 if(d->dp2)
17338 {
17339 font = (FONT*)d->dp2;
17340 }
17341
17342 bool disabled = (d->flags & D_DISABLED) != 0;
17343 if(d->dp)
17344 {
17345 zasm_meta const& meta = *((zasm_meta*)d->dp);
17346 int32_t ind = -1;
17347 d->w = 0;
17348 if(!meta.valid())
17349 {
17350 d->w = txtout(target, "Invalid ZASM metadata found!", d->x, d->y, disabled);
17351 ++ind;
17352 }
17353
17354 int32_t t_w = 0;
17355 char buf[1024];
17356 memset(buf, 0, sizeof(buf));
17357 sprintf(buf, "ZASM Version: %d", meta.zasm_v);
17358 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17359 d->w = zc_max(d->w, t_w);
17360 memset(buf, 0, sizeof(buf));
17361 sprintf(buf, "Metadata Version: %d", meta.meta_v);
17362 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17363 d->w = zc_max(d->w, t_w);
17364 memset(buf, 0, sizeof(buf));
17365 sprintf(buf, "FFScript Version: %d", meta.ffscript_v);
17366 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17367 d->w = zc_max(d->w, t_w);
17368 memset(buf, 0, sizeof(buf));
17369 sprintf(buf, "Script Name: %s", meta.script_name.c_str());
17370 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17371 d->w = zc_max(d->w, t_w);
17372 memset(buf, 0, sizeof(buf));
17373 sprintf(buf, "Author: %s", meta.author.c_str());
17374 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17375 d->w = zc_max(d->w, t_w);
17376 memset(buf, 0, sizeof(buf));
17377 sprintf(buf, "Script Type: %s", get_script_name(meta.script_type).c_str());
17378 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17379 d->w = zc_max(d->w, t_w);
17380 for(auto q = 0; q < 4; ++q)
17381 {
17382 if(!meta.attributes[q].size())
17383 continue;
17384 memset(buf, 0, sizeof(buf));
17385 sprintf(buf, "Attributes[%d]: %s", q, meta.attributes[q].c_str());
17386 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17387 d->w = zc_max(d->w, t_w);
17388 }
17389 for(auto q = 0; q < 8; ++q)
17390 {
17391 if(!meta.attribytes[q].size())
17392 continue;
17393 memset(buf, 0, sizeof(buf));
17394 sprintf(buf, "Attribytes[%d]: %s", q, meta.attribytes[q].c_str());
17395 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17396 d->w = zc_max(d->w, t_w);
17397 }
17398 for(auto q = 0; q < 8; ++q)
17399 {
17400 if(!meta.attrishorts[q].size())
17401 continue;
17402 memset(buf, 0, sizeof(buf));
17403 sprintf(buf, "Attrishorts[%d]: %s", q, meta.attrishorts[q].c_str());
17404 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17405 d->w = zc_max(d->w, t_w);
17406 }
17407 bool indentrun = false;
17408 int32_t run_indent = txtout(NULL, "void run(", 0, 0, false);
17409 std::ostringstream oss;
17410 oss << "void run(";
17411 for(int32_t q = 0; q < 8; ++q)
17412 {
17413 if(!meta.run_idens[q].size() || meta.run_types[q] == ZMETA_NULL_TYPE) continue;
17414 if(q > 0)
17415 oss << ", ";
17416 string type_name = ZScript::getDataTypeName(meta.run_types[q]);
17417 lowerstr(type_name); //all lowercase for this output
17418 if(oss.str().size() > unsigned(indentrun ? 41 : 50))
17419 {
17420 memset(buf, 0, sizeof(buf));
17421 sprintf(buf, "%s", oss.str().c_str());
17422 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
17423 d->w = zc_max(d->w, t_w);
17424 oss.str("");
17425 indentrun = true;
17426 }
17427 oss << type_name.c_str() << " " << meta.run_idens[q];
17428 }
17429 oss << ");";
17430 memset(buf, 0, sizeof(buf));
17431 sprintf(buf, "%s", oss.str().c_str());
17432 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
17433 d->w = zc_max(d->w, t_w);
17434 memset(buf, 0, sizeof(buf));
17435 sprintf(buf, "Compiler Version: %d.%d.%d.%d", meta.compiler_v1, meta.compiler_v2, meta.compiler_v3, meta.compiler_v4);
17436 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17437 d->w = zc_max(d->w, t_w);
17438 memset(buf, 0, sizeof(buf));
17439 sprintf(buf, "Parser-generated: %s", (meta.flags & ZMETA_AUTOGEN)!=0 ? "TRUE" : "FALSE");
17440 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
17441 d->w = zc_max(d->w, t_w);
17442 d->h = (++ind) * (text_height(font) + 3) -3;
17443 }
17444 else
17445 {
17446 d->w = txtout(target, "No ZASM metadata found!", d->x, d->y, disabled);
17447 d->h = text_height(font);
17448 }
17449
17450 if(d->dp3) //function trigger
17451 {
17452 typedef void (*funcType)(void);
17453 funcType func=reinterpret_cast<funcType>(d->dp3);
17454 func();
17455 }
17456
17457 font = oldfont;
17458 break;
17459 }
17460 }
17461
17462 return ret;
17463 }
17464
17465 void resize_scriptinfo_dlg();
17466
17467 static DIALOG scriptinfo_dlg[] =
17468 {
17469 // x y w h fg bg key flags d1 d2 dp
17470 { jwin_win_proc, 0, 0, 200, 150, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Metadata", NULL, NULL },
17471 { d_dummy_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, NULL },
17472 { jwin_button_proc, 70, 120, 60, 20, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
17473 { jwin_zmeta_proc, 50, 30, 100, 100, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, (void*)resize_scriptinfo_dlg },
17474
17475 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17476 };
17477
17478 void resize_scriptinfo_dlg()
17479 {
17480 DIALOG *meta_proc = &scriptinfo_dlg[3], *window = &scriptinfo_dlg[0], *ok_button = &scriptinfo_dlg[2];
17481 int32_t bmargin = 15, hmargins = 30;
17482 jwin_ulalign_dialog(scriptinfo_dlg);
17483 window->w = hmargins*2 + meta_proc->w;
17484 meta_proc->x = hmargins;
17485 window->h = meta_proc->y + meta_proc->h + ok_button->h + bmargin*2;
17486 ok_button->x = (window->w/2)-(ok_button->w/2);
17487 ok_button->y = meta_proc->y + meta_proc->h + bmargin;
17488 jwin_center_dialog(scriptinfo_dlg);
17489 }
17490
17491 void showScriptInfo(zasm_meta const* meta)
17492 {
17493 scriptinfo_dlg[3].dp = (void*)meta;
17494 scriptinfo_dlg[0].dp2 = get_zc_font(font_lfont);
17495 large_dialog(scriptinfo_dlg);
17496 jwin_zmeta_proc(MSG_START,&scriptinfo_dlg[3],0); //Calculate size before calling dialog
17497 jwin_center_dialog(scriptinfo_dlg);
17498 do_zqdialog(scriptinfo_dlg,2);
17499 }
17500
17501 void write_includepaths();
17502 void call_compile_settings();
17503 int32_t onZScriptCompilerSettings()
17504 {
17505 call_compile_settings();
17506 return D_O_K;
17507 }
17508
17509 void doEditZScript()
17510 {
17511 if(do_box_edit(zScript, "ZScript Buffer", false, false))
17512 mark_save_dirty();
17513 }
17514
17515 std::string qst_cfg_header_from_path(std::string path);
17516 extern char *filepath;
17517 string get_box_cfg_hdr(int num)
17518 {
17519 if(num)
17520 return "misc";
17521 return qst_cfg_header_from_path(filepath);
17522 }
17523
17524 6 void clear_map_states()
17525 {
17526
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(map<int32_t, script_slot_data>::iterator it = ffcmap.begin();
17527 3072 it != ffcmap.end(); ++it)
17528 {
17529 3066 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17530 3066 }
17531
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(map<int32_t, script_slot_data>::iterator it = globalmap.begin();
17532 54 it != globalmap.end(); ++it)
17533 {
17534 48 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17535 48 }
17536
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = itemmap.begin();
17537 1536 it != itemmap.end(); ++it)
17538 {
17539 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17540 1530 }
17541
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = npcmap.begin();
17542 1536 it != npcmap.end(); ++it)
17543 {
17544 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17545 1530 }
17546
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = ewpnmap.begin();
17547 1536 it != ewpnmap.end(); ++it)
17548 {
17549 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17550 1530 }
17551
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = lwpnmap.begin();
17552 1536 it != lwpnmap.end(); ++it)
17553 {
17554 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17555 1530 }
17556
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(map<int32_t, script_slot_data>::iterator it = playermap.begin();
17557 30 it != playermap.end(); ++it)
17558 {
17559 24 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17560 24 }
17561
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = dmapmap.begin();
17562 1536 it != dmapmap.end(); ++it)
17563 {
17564 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17565 1530 }
17566
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = screenmap.begin();
17567 1536 it != screenmap.end(); ++it)
17568 {
17569 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17570 1530 }
17571
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = itemspritemap.begin();
17572 1536 it != itemspritemap.end(); ++it)
17573 {
17574 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17575 1530 }
17576
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(map<int32_t, script_slot_data>::iterator it = comboscriptmap.begin();
17577 3072 it != comboscriptmap.end(); ++it)
17578 {
17579 3066 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
17580 3066 }
17581 6 }
17582
17583 void clearAssignSlotDlg()
17584 {
17585 assignscript_dlg[0].dp2 = get_zc_font(font_lfont);
17586 assignscript_dlg[4].d1 = -1;
17587 assignscript_dlg[5].d1 = -1;
17588 assignscript_dlg[7].d1 = -1;
17589 assignscript_dlg[8].d1 = -1;
17590 assignscript_dlg[10].d1 = -1;
17591 assignscript_dlg[11].d1 = -1;
17592 assignscript_dlg[13].flags = 0;
17593 }
17594
17595 void inc_script_name(string& name)
17596 {
17597 size_t pos = name.find_last_not_of("0123456789");
17598 pos = name.find_first_of("0123456789",pos);
17599 std::ostringstream oss;
17600 if(pos == string::npos)
17601 {
17602 oss << name << 2;
17603 }
17604 else
17605 {
17606 int32_t val = atoi(name.substr(pos).c_str());
17607 oss << name.substr(0,pos) << val+1;
17608 }
17609 name = oss.str();
17610 }
17611
17612 enum script_slot_type
17613 {
17614 type_ffc, type_global, type_itemdata, type_npc, type_lweapon, type_eweapon,
17615 type_hero, type_dmap, type_screen, type_itemsprite, type_combo, type_generic,
17616 type_subscreen, num_types
17617 };
17618 script_slot_type getType(ScriptType type)
17619 {
17620 switch(type)
17621 {
17622 case ScriptType::FFC: return type_ffc;
17623 case ScriptType::Global: return type_global;
17624 case ScriptType::Item: return type_itemdata;
17625 case ScriptType::NPC: return type_npc;
17626 case ScriptType::Lwpn: return type_lweapon;
17627 case ScriptType::Ewpn: return type_eweapon;
17628 case ScriptType::Hero: return type_hero;
17629 case ScriptType::DMap:
17630 case ScriptType::ScriptedActiveSubscreen:
17631 case ScriptType::ScriptedPassiveSubscreen:
17632 case ScriptType::OnMap:
17633 return type_dmap;
17634 case ScriptType::Generic: case ScriptType::GenericFrozen:
17635 return type_generic;
17636 case ScriptType::Screen: return type_screen;
17637 case ScriptType::ItemSprite: return type_itemsprite;
17638 case ScriptType::Combo: return type_combo;
17639 case ScriptType::EngineSubscreen: return type_subscreen;
17640 default: return type_ffc; //Default
17641 }
17642 }
17643 #define SLOTMSGFLAG_MISSING 0x01
17644 #define SLOTMSG_SIZE 512
17645 bool checkSkip(int32_t format, byte flags)
17646 {
17647 switch(format)
17648 {
17649 case SCRIPT_FORMAT_DEFAULT:
17650 return (flags != 0);
17651 case SCRIPT_FORMAT_INVALID:
17652 return ((flags & SLOTMSGFLAG_MISSING)==0);
17653 default: return true;
17654 }
17655 }
17656 void clearAllSlots(int32_t type, byte flags = 0)
17657 {
17658 bound(type,0,num_types-1);
17659 switch(type)
17660 {
17661 case type_ffc:
17662 {
17663 for(int32_t q = 0; q < NUMSCRIPTFFC-1; ++q)
17664 {
17665 if(checkSkip(ffcmap[q].format, flags)) continue;
17666 ffcmap[q].scriptname = "";
17667 ffcmap[q].format = SCRIPT_FORMAT_DEFAULT;
17668 }
17669 break;
17670 }
17671 case type_global:
17672 {
17673 //Start at 1 to not clear Init
17674 for(int32_t q = 1; q < NUMSCRIPTGLOBAL; ++q)
17675 {
17676 if(checkSkip(globalmap[q].format, flags)) continue;
17677 globalmap[q].scriptname = "";
17678 globalmap[q].format = SCRIPT_FORMAT_DEFAULT;
17679 }
17680 break;
17681 }
17682 case type_itemdata:
17683 {
17684 for(int32_t q = 0; q < NUMSCRIPTITEM-1; ++q)
17685 {
17686 if(checkSkip(itemmap[q].format, flags)) continue;
17687 itemmap[q].scriptname = "";
17688 itemmap[q].format = SCRIPT_FORMAT_DEFAULT;
17689 }
17690 break;
17691 }
17692 case type_npc:
17693 {
17694 for(int32_t q = 0; q < NUMSCRIPTGUYS-1; ++q)
17695 {
17696 if(checkSkip(npcmap[q].format, flags)) continue;
17697 npcmap[q].scriptname = "";
17698 npcmap[q].format = SCRIPT_FORMAT_DEFAULT;
17699 }
17700 break;
17701 }
17702 case type_lweapon:
17703 {
17704 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
17705 {
17706 if(checkSkip(lwpnmap[q].format, flags)) continue;
17707 lwpnmap[q].scriptname = "";
17708 lwpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
17709 }
17710 break;
17711 }
17712 case type_eweapon:
17713 {
17714 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
17715 {
17716 if(checkSkip(ewpnmap[q].format, flags)) continue;
17717 ewpnmap[q].scriptname = "";
17718 ewpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
17719 }
17720 break;
17721 }
17722 case type_hero:
17723 {
17724 for(int32_t q = 0; q < NUMSCRIPTHERO-1; ++q)
17725 {
17726 if(checkSkip(playermap[q].format, flags)) continue;
17727 playermap[q].scriptname = "";
17728 playermap[q].format = SCRIPT_FORMAT_DEFAULT;
17729 }
17730 break;
17731 }
17732 case type_dmap:
17733 {
17734 for(int32_t q = 0; q < NUMSCRIPTSDMAP-1; ++q)
17735 {
17736 if(checkSkip(dmapmap[q].format, flags)) continue;
17737 dmapmap[q].scriptname = "";
17738 dmapmap[q].format = SCRIPT_FORMAT_DEFAULT;
17739 }
17740 break;
17741 }
17742 case type_screen:
17743 {
17744 for(int32_t q = 0; q < NUMSCRIPTSCREEN-1; ++q)
17745 {
17746 if(checkSkip(screenmap[q].format, flags)) continue;
17747 screenmap[q].scriptname = "";
17748 screenmap[q].format = SCRIPT_FORMAT_DEFAULT;
17749 }
17750 break;
17751 }
17752 case type_itemsprite:
17753 {
17754 for(int32_t q = 0; q < NUMSCRIPTSITEMSPRITE-1; ++q)
17755 {
17756 if(checkSkip(itemspritemap[q].format, flags)) continue;
17757 itemspritemap[q].scriptname = "";
17758 itemspritemap[q].format = SCRIPT_FORMAT_DEFAULT;
17759 }
17760 break;
17761 }
17762 case type_combo:
17763 {
17764 for(int32_t q = 0; q < NUMSCRIPTSCOMBODATA-1; ++q)
17765 {
17766 if(checkSkip(comboscriptmap[q].format, flags)) continue;
17767 comboscriptmap[q].scriptname = "";
17768 comboscriptmap[q].format = SCRIPT_FORMAT_DEFAULT;
17769 }
17770 break;
17771 }
17772 case type_generic:
17773 {
17774 for(int32_t q = 0; q < NUMSCRIPTSGENERIC-1; ++q)
17775 {
17776 if(checkSkip(genericmap[q].format, flags)) continue;
17777 genericmap[q].scriptname = "";
17778 genericmap[q].format = SCRIPT_FORMAT_DEFAULT;
17779 }
17780 break;
17781 }
17782 case type_subscreen:
17783 {
17784 for(int32_t q = 0; q < NUMSCRIPTSSUBSCREEN-1; ++q)
17785 {
17786 if(checkSkip(subscreenmap[q].format, flags)) continue;
17787 subscreenmap[q].scriptname = "";
17788 subscreenmap[q].format = SCRIPT_FORMAT_DEFAULT;
17789 }
17790 break;
17791 }
17792 }
17793 }
17794
17795 static bool doslots_log_output = false, doslots_comment_output = true;
17796 6 void setup_scriptslot_dlg(char* buf, byte flags)
17797 {
17798 //{ Set up the textbox at the bottom, and auto-resize height based on it
17799 6 int32_t prev_height = assignscript_dlg[14].h;
17800 6 memset(buf, 0, SLOTMSG_SIZE);
17801 //
17802 6 strcpy(buf, "Slots with matching names have been updated.\n");
17803
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(flags & SLOTMSGFLAG_MISSING)
17804 3 strcat(buf,"Scripts prefixed with '--' were not found, and will not function.\n");
17805 6 strcat(buf,"Global scripts named 'Init' will be appended to '~Init'");
17806 //
17807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 SETFLAG(assignscript_dlg[13].flags, D_SELECTED, doslots_log_output);
17808
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 SETFLAG(assignscript_dlg[51].flags, D_SELECTED, doslots_comment_output);
17809 6 assignscript_dlg[14].dp = buf;
17810 6 object_message(&assignscript_dlg[14], MSG_START, 0); //Set the width/height
17811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(int32_t diff = assignscript_dlg[14].h - prev_height) //resize dlg
17812 {
17813 6 int32_t prev_bottom = assignscript_dlg[14].y + prev_height;
17814
2/2
✓ Branch 0 taken 306 times.
✓ Branch 1 taken 6 times.
312 for(int32_t q = 1; assignscript_dlg[q].proc; ++q)
17815 {
17816
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 300 times.
306 if(q==14) continue; //Don't change self
17817
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 24 times.
300 if(assignscript_dlg[q].y < prev_bottom) continue; //above proc
17818 24 assignscript_dlg[q].y += diff;
17819 24 }
17820 6 assignscript_dlg[0].h += diff;
17821 6 jwin_center_dialog(assignscript_dlg);
17822 6 }
17823 //}
17824 6 }
17825
17826 std::string global_slotnames[NUMSCRIPTGLOBAL] = {
17827 "Init",
17828 "Active",
17829 "onExit",
17830 "onSaveLoad",
17831 "onLaunch",
17832 "onContGame",
17833 "onF6Menu",
17834 "onSave",
17835 };
17836 std::string player_slotnames[NUMSCRIPTHERO-1] = {
17837 "Init",
17838 "Active",
17839 "onDeath",
17840 "onWin",
17841 };
17842 6 byte reload_scripts(map<string, disassembled_script_data> &scripts)
17843 {
17844 6 byte slotflags = 0;
17845 char temp[100];
17846
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTFFC-1; i++)
17847 {
17848
2/2
✓ Branch 0 taken 2987 times.
✓ Branch 1 taken 79 times.
3066 if(ffcmap[i].isEmpty())
17849 2987 sprintf(temp, "Slot %d:", i+1);
17850 else
17851 {
17852 79 sprintf(temp, "Slot %d:", i+1);
17853
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 6 times.
79 if(scripts.find(ffcmap[i].scriptname) != scripts.end())
17854 73 ffcmap[i].format = SCRIPT_FORMAT_DEFAULT;
17855 else // Previously loaded script not found
17856 {
17857 6 ffcmap[i].format = SCRIPT_FORMAT_INVALID;
17858 6 slotflags |= SLOTMSGFLAG_MISSING;
17859 }
17860 }
17861 3066 ffcmap[i].slotname = temp;
17862 3066 ffcmap[i].update();
17863 3066 }
17864
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; i++)
17865 {
17866
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 globalmap[i].slotname=fmt::format("{}:",global_slotnames[i]);
17867
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 11 times.
48 if(!globalmap[i].isEmpty())
17868 {
17869
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 if(scripts.find(globalmap[i].scriptname) != scripts.end() || globalmap[i].scriptname == "~Init")
17870 11 globalmap[i].format = SCRIPT_FORMAT_DEFAULT;
17871 else // Unloaded
17872 {
17873 globalmap[i].format = SCRIPT_FORMAT_INVALID;
17874 slotflags |= SLOTMSGFLAG_MISSING;
17875 }
17876 11 }
17877 48 globalmap[i].update();
17878 48 }
17879
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTITEM-1; i++)
17880 {
17881
2/2
✓ Branch 0 taken 1517 times.
✓ Branch 1 taken 13 times.
1530 if(itemmap[i].isEmpty())
17882 1517 sprintf(temp, "Slot %d:", i+1);
17883 else
17884 {
17885 13 sprintf(temp, "Slot %d:", i+1);
17886
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if(scripts.find(itemmap[i].scriptname) != scripts.end())
17887 13 itemmap[i].format = SCRIPT_FORMAT_DEFAULT;
17888 else // Previously loaded script not found
17889 {
17890 itemmap[i].format = SCRIPT_FORMAT_INVALID;
17891 slotflags |= SLOTMSGFLAG_MISSING;
17892 }
17893 }
17894 1530 itemmap[i].slotname = temp;
17895 1530 itemmap[i].update();
17896 1530 }
17897
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTGUYS-1; i++)
17898 {
17899
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(npcmap[i].isEmpty())
17900 1530 sprintf(temp, "Slot %d:", i+1);
17901 else
17902 {
17903 sprintf(temp, "Slot %d:", i+1);
17904 if(scripts.find(npcmap[i].scriptname) != scripts.end())
17905 npcmap[i].format = SCRIPT_FORMAT_DEFAULT;
17906 else // Previously loaded script not found
17907 {
17908 npcmap[i].format = SCRIPT_FORMAT_INVALID;
17909 slotflags |= SLOTMSGFLAG_MISSING;
17910 }
17911 }
17912 1530 npcmap[i].slotname = temp;
17913 1530 npcmap[i].update();
17914 1530 }
17915
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
17916 {
17917
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(ewpnmap[i].isEmpty())
17918 1530 sprintf(temp, "Slot %d:", i+1);
17919 else
17920 {
17921 sprintf(temp, "Slot %d:", i+1);
17922 if(scripts.find(ewpnmap[i].scriptname) != scripts.end())
17923 ewpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
17924 else // Previously loaded script not found
17925 {
17926 ewpnmap[i].format = SCRIPT_FORMAT_INVALID;
17927 slotflags |= SLOTMSGFLAG_MISSING;
17928 }
17929 }
17930 1530 ewpnmap[i].slotname = temp;
17931 1530 ewpnmap[i].update();
17932 1530 }
17933
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
17934 {
17935
2/2
✓ Branch 0 taken 1529 times.
✓ Branch 1 taken 1 times.
1530 if(lwpnmap[i].isEmpty())
17936 1529 sprintf(temp, "Slot %d:", i+1);
17937 else
17938 {
17939 1 sprintf(temp, "Slot %d:", i+1);
17940
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(scripts.find(lwpnmap[i].scriptname) != scripts.end())
17941 1 lwpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
17942 else // Previously loaded script not found
17943 {
17944 lwpnmap[i].format = SCRIPT_FORMAT_INVALID;
17945 slotflags |= SLOTMSGFLAG_MISSING;
17946 }
17947 }
17948 1530 lwpnmap[i].slotname = temp;
17949 1530 lwpnmap[i].update();
17950 1530 }
17951
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(int32_t i = 0; i < NUMSCRIPTHERO-1; i++)
17952 {
17953
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 playermap[i].slotname=fmt::format("{}:",player_slotnames[i]);
17954
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!playermap[i].isEmpty())
17955 {
17956 if(scripts.find(playermap[i].scriptname) != scripts.end())
17957 playermap[i].format = SCRIPT_FORMAT_DEFAULT;
17958 else // Unloaded
17959 {
17960 playermap[i].format = SCRIPT_FORMAT_INVALID;
17961 slotflags |= SLOTMSGFLAG_MISSING;
17962 }
17963 }
17964 24 playermap[i].update();
17965 24 }
17966
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSCREEN-1; i++)
17967 {
17968
2/2
✓ Branch 0 taken 1528 times.
✓ Branch 1 taken 2 times.
1530 if(screenmap[i].isEmpty())
17969 1528 sprintf(temp, "Slot %d:", i+1);
17970 else
17971 {
17972 2 sprintf(temp, "Slot %d:", i+1);
17973
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(scripts.find(screenmap[i].scriptname) != scripts.end())
17974 2 screenmap[i].format = SCRIPT_FORMAT_DEFAULT;
17975 else // Previously loaded script not found
17976 {
17977 screenmap[i].format = SCRIPT_FORMAT_INVALID;
17978 slotflags |= SLOTMSGFLAG_MISSING;
17979 }
17980 }
17981 1530 screenmap[i].slotname = temp;
17982 1530 screenmap[i].update();
17983 1530 }
17984
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSDMAP-1; i++)
17985 {
17986
2/2
✓ Branch 0 taken 1525 times.
✓ Branch 1 taken 5 times.
1530 if(dmapmap[i].isEmpty())
17987 1525 sprintf(temp, "Slot %d:", i+1);
17988 else
17989 {
17990 5 sprintf(temp, "Slot %d:", i+1);
17991
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(scripts.find(dmapmap[i].scriptname) != scripts.end())
17992 5 dmapmap[i].format = SCRIPT_FORMAT_DEFAULT;
17993 else // Previously loaded script not found
17994 {
17995 dmapmap[i].format = SCRIPT_FORMAT_INVALID;
17996 slotflags |= SLOTMSGFLAG_MISSING;
17997 }
17998 }
17999 1530 dmapmap[i].slotname = temp;
18000 1530 dmapmap[i].update();
18001 1530 }
18002
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE-1; i++)
18003 {
18004
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(itemspritemap[i].isEmpty())
18005 1530 sprintf(temp, "Slot %d:", i+1);
18006 else
18007 {
18008 sprintf(temp, "Slot %d:", i+1);
18009 if(scripts.find(itemspritemap[i].scriptname) != scripts.end())
18010 itemspritemap[i].format = SCRIPT_FORMAT_DEFAULT;
18011 else // Previously loaded script not found
18012 {
18013 itemspritemap[i].format = SCRIPT_FORMAT_INVALID;
18014 slotflags |= SLOTMSGFLAG_MISSING;
18015 }
18016 }
18017 1530 itemspritemap[i].slotname = temp;
18018 1530 itemspritemap[i].update();
18019 1530 }
18020
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA-1; i++)
18021 {
18022
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(comboscriptmap[i].isEmpty())
18023 3066 sprintf(temp, "Slot %d:", i+1);
18024 else
18025 {
18026 sprintf(temp, "Slot %d:", i+1);
18027 if(scripts.find(comboscriptmap[i].scriptname) != scripts.end())
18028 comboscriptmap[i].format = SCRIPT_FORMAT_DEFAULT;
18029 else // Previously loaded script not found
18030 {
18031 comboscriptmap[i].format = SCRIPT_FORMAT_INVALID;
18032 slotflags |= SLOTMSGFLAG_MISSING;
18033 }
18034 }
18035 3066 comboscriptmap[i].slotname = temp;
18036 3066 comboscriptmap[i].update();
18037 3066 }
18038
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTSGENERIC-1; i++)
18039 {
18040
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 22 times.
3066 if(genericmap[i].isEmpty())
18041 3044 sprintf(temp, "Slot %d:", i+1);
18042 else
18043 {
18044 22 sprintf(temp, "Slot %d:", i+1);
18045
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 1 times.
22 if(scripts.find(genericmap[i].scriptname) != scripts.end())
18046 21 genericmap[i].format = SCRIPT_FORMAT_DEFAULT;
18047 else // Previously loaded script not found
18048 {
18049 1 genericmap[i].format = SCRIPT_FORMAT_INVALID;
18050 1 slotflags |= SLOTMSGFLAG_MISSING;
18051 }
18052 }
18053 3066 genericmap[i].slotname = temp;
18054 3066 genericmap[i].update();
18055 3066 }
18056
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSSUBSCREEN-1; i++)
18057 {
18058
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(subscreenmap[i].isEmpty())
18059 1530 sprintf(temp, "Slot %d:", i+1);
18060 else
18061 {
18062 sprintf(temp, "Slot %d:", i+1);
18063 if(scripts.find(subscreenmap[i].scriptname) != scripts.end())
18064 subscreenmap[i].format = SCRIPT_FORMAT_DEFAULT;
18065 else // Previously loaded script not found
18066 {
18067 subscreenmap[i].format = SCRIPT_FORMAT_INVALID;
18068 slotflags |= SLOTMSGFLAG_MISSING;
18069 }
18070 }
18071 1530 subscreenmap[i].slotname = temp;
18072 1530 subscreenmap[i].update();
18073 1530 }
18074 6 return slotflags;
18075 }
18076
18077 void doClearSlots(byte* flags);
18078
18079 static map<string, disassembled_script_data> *doslot_scripts = nullptr;
18080 21510 bool handle_slot(script_slot_data& slotdata, script_data* scriptdata)
18081 {
18082
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 21384 times.
21510 if(slotdata.hasScriptData())
18083 {
18084 126 auto& data = (*doslot_scripts)[slotdata.scriptname];
18085 126 scriptdata->meta = data.meta;
18086 126 scriptdata->pc = data.pc;
18087 126 scriptdata->end_pc = data.end_pc;
18088 126 scriptdata->zasm_script = zasm_scripts[0];
18089 126 }
18090
1/2
✓ Branch 0 taken 21384 times.
✗ Branch 1 not taken.
21384 else if(scriptdata)
18091 {
18092 21384 scriptdata->zasm_script = nullptr;
18093 21384 scriptdata->meta.zero();
18094 21384 scriptdata->pc = 0;
18095 21384 scriptdata->end_pc = 0;
18096 21384 }
18097 21510 return true;
18098 }
18099 78 bool handle_slot_map(map<int32_t, script_slot_data>& mp, int offs, script_data** scriptdata)
18100 {
18101
2/2
✓ Branch 0 taken 21510 times.
✓ Branch 1 taken 78 times.
21588 for(auto it = mp.begin(); it != mp.end(); it++)
18102 {
18103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21510 times.
21510 if(!handle_slot(it->second, scriptdata[it->first + offs]))
18104 return false;
18105 21510 }
18106 78 return true;
18107 78 }
18108
18109 void smart_slot_named(map<string, disassembled_script_data> &scripts,
18110 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
18111 std::string* slotnames, int slotstart, int slotend)
18112 {
18113 for(int q = slotstart; q < slotend; ++q)
18114 {
18115 auto& lval = mp[q];
18116 if(!lval.isEmpty())
18117 continue; //occupied, leave alone
18118 bool done = false;
18119 if(!done) //Check case-sensitive
18120 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
18121 {
18122 auto const& rval = scriptnames[rind];
18123 if(rval == "<none>") continue;
18124 if(rval == slotnames[q])
18125 { //Perfect match
18126 lval.updateName(rval);
18127 lval.format = scripts[lval.scriptname].format;
18128 done = true;
18129 break;
18130 }
18131 }
18132 if(!done) //Check case-insensitive
18133 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
18134 {
18135 auto const& rval = scriptnames[rind];
18136 if(rval == "<none>") continue;
18137 string lc_rv = rval, lc_slot = slotnames[q];
18138 lowerstr(lc_rv);
18139 lowerstr(lc_slot);
18140 if(lc_rv == lc_slot)
18141 { //Insensitive match
18142 lval.updateName(rval);
18143 lval.format = scripts[lval.scriptname].format;
18144 break;
18145 }
18146 }
18147 }
18148 }
18149 void smart_slot_type(map<string, disassembled_script_data> &scripts,
18150 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
18151 int slotcount)
18152 {
18153 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
18154 {
18155 auto const& rval = scriptnames[rind];
18156 if(rval == "<none>") continue;
18157 script_slot_data* first_open_slot = nullptr;
18158 bool done = false;
18159 for(int q = 0; q < slotcount; ++q)
18160 {
18161 auto& lval = mp[q];
18162 if(lval.isEmpty())
18163 {
18164 if(!first_open_slot)
18165 first_open_slot = &lval;
18166 }
18167 else if(lval.scriptname == rval)
18168 {
18169 done = true;
18170 break;
18171 }
18172 }
18173 if(!done)
18174 {
18175 if(!first_open_slot)
18176 break; //no slots left to assign to!
18177 first_open_slot->updateName(rval);
18178 first_open_slot->format = scripts[first_open_slot->scriptname].format;
18179 }
18180 }
18181 }
18182
18183 6 bool do_slots(vector<shared_ptr<ZScript::Opcode>> const& zasm,
18184 map<string, disassembled_script_data> &scripts, int assign_mode)
18185 {
18186 6 large_dialog(assignscript_dlg);
18187 6 int32_t ret = 3;
18188 6 char slots_msg[SLOTMSG_SIZE] = {0};
18189 6 byte slotflags = reload_scripts(scripts);
18190 6 setup_scriptslot_dlg(slots_msg, slotflags);
18191 6 bool retval = false;
18192
18193 6 popup_zqdialog_start();
18194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 while(!assign_mode)
18195 {
18196 slotflags = reload_scripts(scripts);
18197 ret = do_zqdialog(assignscript_dlg, ret);
18198
18199 switch(ret)
18200 {
18201 case 0:
18202 case 2:
18203 //Cancel
18204 goto exit_do_slots;
18205
18206 case 3: goto auto_do_slots;
18207
18208 case 6:
18209 //<<, FFC
18210 {
18211 int32_t lind = assignscript_dlg[4].d1;
18212 int32_t rind = assignscript_dlg[5].d1;
18213
18214 if(lind < 0 || rind < 0)
18215 break;
18216
18217 if(asffcscripts[rind] == "<none>")
18218 {
18219 ffcmap[lind].scriptname = "";
18220 ffcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18221 }
18222 else
18223 {
18224 ffcmap[lind].updateName(asffcscripts[rind]);
18225 ffcmap[lind].format = scripts[ffcmap[lind].scriptname].format;
18226 }
18227
18228 break;
18229 }
18230 case 9:
18231 //<<, Global
18232 {
18233 int32_t lind = assignscript_dlg[7].d1;
18234 int32_t rind = assignscript_dlg[8].d1;
18235
18236 if(lind < 0 || rind < 0)
18237 break;
18238
18239 if(lind == 0)
18240 {
18241 displayinfo("Error","ZScript reserves this slot.");
18242 break;
18243 }
18244
18245 if(asglobalscripts[rind] == "<none>")
18246 {
18247 globalmap[lind].scriptname = "";
18248 globalmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18249 }
18250 else
18251 {
18252 globalmap[lind].updateName(asglobalscripts[rind]);
18253 globalmap[lind].format = scripts[globalmap[lind].scriptname].format;
18254 }
18255
18256 break;
18257 }
18258 case 12:
18259 //<<, ITEM
18260 {
18261 int32_t lind = assignscript_dlg[10].d1;
18262 int32_t rind = assignscript_dlg[11].d1;
18263
18264 if(lind < 0 || rind < 0)
18265 break;
18266
18267 if(asitemscripts[rind] == "<none>")
18268 {
18269 itemmap[lind].scriptname = "";
18270 itemmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18271 }
18272 else
18273 {
18274 itemmap[lind].updateName(asitemscripts[rind]);
18275 itemmap[lind].format = scripts[itemmap[lind].scriptname].format;
18276 }
18277
18278 break;
18279 }
18280 case 20:
18281 //<<, NPC
18282 {
18283 int32_t lind = assignscript_dlg[18].d1;
18284 int32_t rind = assignscript_dlg[19].d1;
18285
18286 if(lind < 0 || rind < 0)
18287 break;
18288
18289 if(asnpcscripts[rind] == "<none>")
18290 {
18291 npcmap[lind].scriptname = "";
18292 npcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18293 }
18294 else
18295 {
18296 npcmap[lind].updateName(asnpcscripts[rind]);
18297 npcmap[lind].format = scripts[npcmap[lind].scriptname].format;
18298 }
18299
18300 break;
18301 }
18302 case 23:
18303 //<<, LWeapon
18304 {
18305 int32_t lind = assignscript_dlg[21].d1;
18306 int32_t rind = assignscript_dlg[22].d1;
18307
18308 if(lind < 0 || rind < 0)
18309 break;
18310
18311 if(aslweaponscripts[rind] == "<none>")
18312 {
18313 lwpnmap[lind].scriptname = "";
18314 lwpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18315 }
18316 else
18317 {
18318 lwpnmap[lind].updateName(aslweaponscripts[rind]);
18319 lwpnmap[lind].format = scripts[lwpnmap[lind].scriptname].format;
18320 }
18321
18322 break;
18323 }
18324 case 26:
18325 //<<, EWeapon
18326 {
18327 int32_t lind = assignscript_dlg[24].d1;
18328 int32_t rind = assignscript_dlg[25].d1;
18329
18330 if(lind < 0 || rind < 0)
18331 break;
18332
18333 if(aseweaponscripts[rind] == "<none>")
18334 {
18335 ewpnmap[lind].scriptname = "";
18336 ewpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18337 }
18338 else
18339 {
18340 ewpnmap[lind].updateName(aseweaponscripts[rind]);
18341 ewpnmap[lind].format = scripts[ewpnmap[lind].scriptname].format;
18342 }
18343
18344 break;
18345 }
18346 case 29:
18347 //<<, Hero
18348 {
18349 int32_t lind = assignscript_dlg[27].d1;
18350 int32_t rind = assignscript_dlg[28].d1;
18351
18352 if(lind < 0 || rind < 0)
18353 break;
18354
18355 if(asplayerscripts[rind] == "<none>")
18356 {
18357 playermap[lind].scriptname = "";
18358 playermap[lind].format = SCRIPT_FORMAT_DEFAULT;
18359 }
18360 else
18361 {
18362 playermap[lind].updateName(asplayerscripts[rind]);
18363 playermap[lind].format = scripts[playermap[lind].scriptname].format;
18364 }
18365
18366 break;
18367 }
18368 case 32:
18369 //<<, Screendata
18370 {
18371 int32_t lind = assignscript_dlg[30].d1;
18372 int32_t rind = assignscript_dlg[31].d1;
18373
18374 if(lind < 0 || rind < 0)
18375 break;
18376
18377 if(asscreenscripts[rind] == "<none>")
18378 {
18379 screenmap[lind].scriptname = "";
18380 screenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18381 }
18382 else
18383 {
18384 screenmap[lind].updateName(asscreenscripts[rind]);
18385 screenmap[lind].format = scripts[screenmap[lind].scriptname].format;
18386 }
18387
18388 break;
18389 }
18390 case 35:
18391 //<<, dmapdata
18392 {
18393 int32_t lind = assignscript_dlg[33].d1;
18394 int32_t rind = assignscript_dlg[34].d1;
18395
18396 if(lind < 0 || rind < 0)
18397 break;
18398
18399 if(asdmapscripts[rind] == "<none>")
18400 {
18401 dmapmap[lind].scriptname = "";
18402 dmapmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18403 }
18404 else
18405 {
18406 dmapmap[lind].updateName(asdmapscripts[rind]);
18407 dmapmap[lind].format = scripts[dmapmap[lind].scriptname].format;
18408 }
18409
18410 break;
18411 }
18412 case 38:
18413 //<<, itemsprite
18414 {
18415 int32_t lind = assignscript_dlg[36].d1;
18416 int32_t rind = assignscript_dlg[37].d1;
18417
18418 if(lind < 0 || rind < 0)
18419 break;
18420
18421 if(asitemspritescripts[rind] == "<none>")
18422 {
18423 itemspritemap[lind].scriptname = "";
18424 itemspritemap[lind].format = SCRIPT_FORMAT_DEFAULT;
18425 }
18426 else
18427 {
18428 itemspritemap[lind].updateName(asitemspritescripts[rind]);
18429 itemspritemap[lind].format = scripts[itemspritemap[lind].scriptname].format;
18430 }
18431
18432 break;
18433 }
18434 case 41:
18435 //<<, comboscript
18436 {
18437 int32_t lind = assignscript_dlg[39].d1;
18438 int32_t rind = assignscript_dlg[40].d1;
18439
18440 if(lind < 0 || rind < 0)
18441 break;
18442
18443 if(ascomboscripts[rind] == "<none>")
18444 {
18445 comboscriptmap[lind].scriptname = "";
18446 comboscriptmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18447 }
18448 else
18449 {
18450 comboscriptmap[lind].updateName(ascomboscripts[rind]);
18451 comboscriptmap[lind].format = scripts[comboscriptmap[lind].scriptname].format;
18452 }
18453
18454 break;
18455 }
18456 case 47:
18457 //<<, generic script
18458 {
18459 int32_t lind = assignscript_dlg[45].d1;
18460 int32_t rind = assignscript_dlg[46].d1;
18461
18462 if(lind < 0 || rind < 0)
18463 break;
18464
18465 if(asgenericscripts[rind] == "<none>")
18466 {
18467 genericmap[lind].scriptname = "";
18468 genericmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18469 }
18470 else
18471 {
18472 genericmap[lind].updateName(asgenericscripts[rind]);
18473 genericmap[lind].format = scripts[genericmap[lind].scriptname].format;
18474 }
18475
18476 break;
18477 }
18478 case 50:
18479 //<<, subscreen script
18480 {
18481 int32_t lind = assignscript_dlg[48].d1;
18482 int32_t rind = assignscript_dlg[49].d1;
18483
18484 if(lind < 0 || rind < 0)
18485 break;
18486
18487 if(assubscreenscripts[rind] == "<none>")
18488 {
18489 subscreenmap[lind].scriptname = "";
18490 subscreenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
18491 }
18492 else
18493 {
18494 subscreenmap[lind].updateName(assubscreenscripts[rind]);
18495 subscreenmap[lind].format = scripts[subscreenmap[lind].scriptname].format;
18496 }
18497
18498 break;
18499 }
18500
18501 case 42:
18502 //Script Info, information
18503 {
18504 disassembled_script_data* target = nullptr;
18505 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
18506 {
18507 default:
18508 case 0: //FFC
18509 {
18510 int32_t id = assignscript_dlg[4].d1;
18511 if(id > -1 && ffcmap[id].hasScriptData())
18512 {
18513 target = &(scripts[ffcmap[id].scriptname]);
18514 }
18515 break;
18516 }
18517 case 1: //Global
18518 {
18519 int32_t id = assignscript_dlg[7].d1;
18520 if(id > -1 && globalmap[id].hasScriptData())
18521 {
18522 target = &(scripts[globalmap[id].scriptname]);
18523 }
18524 break;
18525 }
18526 case 2: //Item
18527 {
18528 int32_t id = assignscript_dlg[10].d1;
18529 if(id > -1 && itemmap[id].hasScriptData())
18530 {
18531 target = &(scripts[itemmap[id].scriptname]);
18532 }
18533 break;
18534 }
18535 case 3: //npc
18536 {
18537 int32_t id = assignscript_dlg[19].d1;
18538 if(id > -1 && npcmap[id].hasScriptData())
18539 {
18540 target = &(scripts[npcmap[id].scriptname]);
18541 }
18542 break;
18543 }
18544 case 4: //lweapon
18545 {
18546 int32_t id = assignscript_dlg[21].d1;
18547 if(id > -1 && lwpnmap[id].hasScriptData())
18548 {
18549 target = &(scripts[lwpnmap[id].scriptname]);
18550 }
18551 break;
18552 }
18553 case 5: //eweapon
18554 {
18555 int32_t id = assignscript_dlg[24].d1;
18556 if(id > -1 && ewpnmap[id].hasScriptData())
18557 {
18558 target = &(scripts[ewpnmap[id].scriptname]);
18559 }
18560 break;
18561 }
18562 case 6: //hero
18563 {
18564 int32_t id = assignscript_dlg[27].d1;
18565 if(id > -1 && playermap[id].hasScriptData())
18566 {
18567 target = &(scripts[playermap[id].scriptname]);
18568 }
18569 break;
18570 }
18571 case 7: //dmap
18572 {
18573 int32_t id = assignscript_dlg[33].d1;
18574 if(id > -1 && dmapmap[id].hasScriptData())
18575 {
18576 target = &(scripts[dmapmap[id].scriptname]);
18577 }
18578 break;
18579 }
18580 case 8: //screen
18581 {
18582 int32_t id = assignscript_dlg[30].d1;
18583 if(id > -1 && screenmap[id].hasScriptData())
18584 {
18585 target = &(scripts[screenmap[id].scriptname]);
18586 }
18587 break;
18588 }
18589 case 9: //itemsprite
18590 {
18591 int32_t id = assignscript_dlg[36].d1;
18592 if(id > -1 && itemspritemap[id].hasScriptData())
18593 {
18594 target = &(scripts[itemspritemap[id].scriptname]);
18595 }
18596 break;
18597 }
18598 case 10: //combo
18599 {
18600 int32_t id = assignscript_dlg[39].d1;
18601 if(id > -1 && comboscriptmap[id].hasScriptData())
18602 {
18603 target = &(scripts[comboscriptmap[id].scriptname]);
18604 }
18605 break;
18606 }
18607 case 11: //Generic
18608 {
18609 int32_t id = assignscript_dlg[45].d1;
18610 if(id > -1 && genericmap[id].hasScriptData())
18611 {
18612 target = &(scripts[genericmap[id].scriptname]);
18613 }
18614 break;
18615 }
18616 case 12: //Subscreen
18617 {
18618 int32_t id = assignscript_dlg[48].d1;
18619 if(id > -1 && subscreenmap[id].hasScriptData())
18620 {
18621 target = &(scripts[subscreenmap[id].scriptname]);
18622 }
18623 break;
18624 }
18625 }
18626 if(target)
18627 showScriptInfo(&target->meta);
18628 break;
18629 }
18630
18631 case 43:
18632 //Script Info, information
18633 {
18634 disassembled_script_data* target = NULL;
18635 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
18636 {
18637 default:
18638 case 0: //FFC
18639 {
18640 int32_t id = assignscript_dlg[5].d1;
18641 if(id < 0 || asffcscripts[id] == "<none>" || asffcscripts[id].at(0) == '-') break;
18642 target = &(scripts[asffcscripts[id]]);
18643 break;
18644 }
18645 case 1: //Global
18646 {
18647 int32_t id = assignscript_dlg[8].d1;
18648 if(id < 0 || asglobalscripts[id] == "<none>" || asglobalscripts[id].at(0) == '-') break;
18649 target = &(scripts[asglobalscripts[id]]);
18650 break;
18651 }
18652 case 2: //Item
18653 {
18654 int32_t id = assignscript_dlg[11].d1;
18655 if(id < 0 || asitemscripts[id] == "<none>" || asitemscripts[id].at(0) == '-') break;
18656 target = &(scripts[asitemscripts[id]]);
18657 break;
18658 }
18659 case 3: //npc
18660 {
18661 int32_t id = assignscript_dlg[20].d1;
18662 if(id < 0 || asnpcscripts[id] == "<none>" || asnpcscripts[id].at(0) == '-') break;
18663 target = &(scripts[asnpcscripts[id]]);
18664 break;
18665 }
18666 case 4: //lweapon
18667 {
18668 int32_t id = assignscript_dlg[22].d1;
18669 if(id < 0 || aslweaponscripts[id] == "<none>" || aslweaponscripts[id].at(0) == '-') break;
18670 target = &(scripts[aslweaponscripts[id]]);
18671 break;
18672 }
18673 case 5: //eweapon
18674 {
18675 int32_t id = assignscript_dlg[25].d1;
18676 if(id < 0 || aseweaponscripts[id] == "<none>" || aseweaponscripts[id].at(0) == '-') break;
18677 target = &(scripts[aseweaponscripts[id]]);
18678 break;
18679 }
18680 case 6: //hero
18681 {
18682 int32_t id = assignscript_dlg[28].d1;
18683 if(id < 0 || asplayerscripts[id] == "<none>" || asplayerscripts[id].at(0) == '-') break;
18684 target = &(scripts[asplayerscripts[id]]);
18685 break;
18686 }
18687 case 7: //dmap
18688 {
18689 int32_t id = assignscript_dlg[34].d1;
18690 if(id < 0 || asdmapscripts[id] == "<none>" || asdmapscripts[id].at(0) == '-') break;
18691 target = &(scripts[asdmapscripts[id]]);
18692 break;
18693 }
18694 case 8: //screen
18695 {
18696 int32_t id = assignscript_dlg[31].d1;
18697 if(id < 0 || asscreenscripts[id] == "<none>" || asscreenscripts[id].at(0) == '-') break;
18698 target = &(scripts[asscreenscripts[id]]);
18699 break;
18700 }
18701 case 9: //itemsprite
18702 {
18703 int32_t id = assignscript_dlg[37].d1;
18704 if(id < 0 || asitemspritescripts[id] == "<none>" || asitemspritescripts[id].at(0) == '-') break;
18705 target = &(scripts[asitemspritescripts[id]]);
18706 break;
18707 }
18708 case 10: //combo
18709 {
18710 int32_t id = assignscript_dlg[40].d1;
18711 if(id < 0 || ascomboscripts[id] == "<none>" || ascomboscripts[id].at(0) == '-') break;
18712 target = &(scripts[ascomboscripts[id]]);
18713 break;
18714 }
18715 case 11: //generic
18716 {
18717 int32_t id = assignscript_dlg[46].d1;
18718 if(id < 0 || asgenericscripts[id] == "<none>" || asgenericscripts[id].at(0) == '-') break;
18719 target = &(scripts[asgenericscripts[id]]);
18720 break;
18721 }
18722 case 12: //subscreen
18723 {
18724 int32_t id = assignscript_dlg[49].d1;
18725 if(id < 0 || assubscreenscripts[id] == "<none>" || assubscreenscripts[id].at(0) == '-') break;
18726 target = &(scripts[assubscreenscripts[id]]);
18727 break;
18728 }
18729 }
18730 if(target)
18731 showScriptInfo(&target->meta);
18732 break;
18733 }
18734
18735 case 44:
18736 //Clear, clear slots of current type- after a confirmation.
18737 {
18738 doClearSlots(&slotflags);
18739 break;
18740 }
18741 }
18742 }
18743
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(assign_mode == 2) //Smart Assign
18744 {
18745 //For global/hero scripts, match slot names if unoccupied
18746 smart_slot_named(scripts, asglobalscripts, globalmap, global_slotnames, 1, NUMSCRIPTGLOBAL);
18747 smart_slot_named(scripts, asplayerscripts, playermap, player_slotnames, 0, NUMSCRIPTHERO-1);
18748 //For other scripts, assign all un-assigned scripts
18749 smart_slot_type(scripts, asffcscripts, ffcmap, NUMSCRIPTFFC-1);
18750 smart_slot_type(scripts, asitemscripts, itemmap, NUMSCRIPTITEM-1);
18751 smart_slot_type(scripts, asnpcscripts, npcmap, NUMSCRIPTGUYS-1);
18752 smart_slot_type(scripts, aslweaponscripts, lwpnmap, NUMSCRIPTWEAPONS-1);
18753 smart_slot_type(scripts, aseweaponscripts, ewpnmap, NUMSCRIPTWEAPONS-1);
18754 smart_slot_type(scripts, asscreenscripts, screenmap, NUMSCRIPTSCREEN-1);
18755 smart_slot_type(scripts, asdmapscripts, dmapmap, NUMSCRIPTSDMAP-1);
18756 smart_slot_type(scripts, asitemspritescripts, itemspritemap, NUMSCRIPTSITEMSPRITE-1);
18757 smart_slot_type(scripts, ascomboscripts, comboscriptmap, NUMSCRIPTSCOMBODATA-1);
18758 smart_slot_type(scripts, asgenericscripts, genericmap, NUMSCRIPTSGENERIC-1);
18759 smart_slot_type(scripts, assubscreenscripts, subscreenmap, NUMSCRIPTSSUBSCREEN-1);
18760 }
18761 auto_do_slots:
18762 6 doslots_log_output = (assignscript_dlg[13].flags == D_SELECTED);
18763 6 doslots_comment_output = (assignscript_dlg[51].flags == D_SELECTED);
18764 6 doslot_scripts = &scripts;
18765 //OK
18766 {
18767
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(doslots_log_output)
18768 {
18769 string outstr;
18770 write_script(zasm, outstr, doslots_comment_output, doslot_scripts);
18771 safe_al_trace(outstr);
18772 }
18773 6 auto start_assign_time = std::chrono::steady_clock::now();
18774 6 string zasm_str;
18775
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 write_script(zasm, zasm_str, false, nullptr);
18776
18777 6 std::vector<ffscript> zasm;
18778
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(parse_script_string(zasm, zasm_str, false))
18779 goto exit_do_slots;
18780
18781 6 zasm_scripts.clear();
18782
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 zasm_scripts.emplace_back(std::make_shared<zasm_script>(std::move(zasm)));
18783
18784
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(ffcmap, 1, ffscripts))
18785 goto exit_do_slots;
18786
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(globalmap, 0, globalscripts))
18787 goto exit_do_slots;
18788
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(itemmap, 1, itemscripts))
18789 goto exit_do_slots;
18790
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(npcmap, 1, guyscripts))
18791 goto exit_do_slots;
18792
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(lwpnmap, 1, lwpnscripts))
18793 goto exit_do_slots;
18794
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(ewpnmap, 1, ewpnscripts))
18795 goto exit_do_slots;
18796
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(playermap, 1, playerscripts))
18797 goto exit_do_slots;
18798
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(dmapmap, 1, dmapscripts))
18799 goto exit_do_slots;
18800
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(screenmap, 1, screenscripts))
18801 goto exit_do_slots;
18802
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(itemspritemap, 1, itemspritescripts))
18803 goto exit_do_slots;
18804
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(comboscriptmap, 1, comboscripts))
18805 goto exit_do_slots;
18806
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(genericmap, 1, genericscripts))
18807 goto exit_do_slots;
18808
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(subscreenmap, 1, subscreenscripts))
18809 goto exit_do_slots;
18810
18811 6 auto end_assign_time = std::chrono::steady_clock::now();
18812
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 int compile_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end_assign_time - start_assign_time).count();
18813
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 al_trace("Assign Slots took %d ms\n", compile_time_ms);
18814 6 char buf[256] = {0};
18815 12 sprintf(buf, "ZScripts successfully loaded into script slots"
18816 6 "\nAssign Slots took %d ms", compile_time_ms);
18817
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 auto sfx_id = vbound(zc_get_config("Compiler","compile_finish_sample",20),0,255);
18818
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 auto sfx_vol = vbound(zc_get_config("Compiler","compile_audio_volume",100),0,255);
18819
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if ( sfx_id > 0 && sfx_vol > 0)
18820
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 sfx(sfx_id, 128, false, true, sfx_vol / 1.28_zf);
18821
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!assign_mode)
18822 InfoDialog("Slots Assigned",buf).show();
18823
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 kill_sfx();
18824 6 retval = true;
18825 6 goto exit_do_slots;
18826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 }
18827 exit_do_slots:
18828 6 doslot_scripts = nullptr;
18829 6 popup_zqdialog_end();
18830 6 return retval;
18831 }
18832
18833 static char slottype_str_buf[32];
18834
18835 const char *slottype_list(int32_t index, int32_t *list_size)
18836 {
18837 if(index >= 0)
18838 {
18839 bound(index,0,num_types-1);
18840
18841 switch(index)
18842 {
18843 case type_ffc:
18844 strcpy(slottype_str_buf, "FFC");
18845 break;
18846 case type_global:
18847 strcpy(slottype_str_buf, "Global");
18848 break;
18849 case type_itemdata:
18850 strcpy(slottype_str_buf, "Item");
18851 break;
18852 case type_npc:
18853 strcpy(slottype_str_buf, "NPC");
18854 break;
18855 case type_lweapon:
18856 strcpy(slottype_str_buf, "LWeapon");
18857 break;
18858 case type_eweapon:
18859 strcpy(slottype_str_buf, "EWeapon");
18860 break;
18861 case type_hero:
18862 strcpy(slottype_str_buf, "Hero");
18863 break;
18864 case type_dmap:
18865 strcpy(slottype_str_buf, "DMap");
18866 break;
18867 case type_screen:
18868 strcpy(slottype_str_buf, "Screen");
18869 break;
18870 case type_itemsprite:
18871 strcpy(slottype_str_buf, "ItemSprite");
18872 break;
18873 case type_combo:
18874 strcpy(slottype_str_buf, "Combo");
18875 break;
18876 case type_generic:
18877 strcpy(slottype_str_buf, "Generic");
18878 break;
18879 case type_subscreen:
18880 strcpy(slottype_str_buf, "Subscreen");
18881 break;
18882 }
18883
18884 return slottype_str_buf;
18885 }
18886 *list_size = 11;
18887 return NULL;
18888 }
18889 12 static ListData slottype_sel_list(slottype_list, &font);
18890
18891 static DIALOG clearslots_dlg[] =
18892 {
18893 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear Slots", NULL, NULL },
18894 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
18895 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
18896 12 { jwin_droplist_proc, 50, 28+16, 70, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
18897 12 { jwin_radio_proc, 40, 34+00, 81, 9, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Clear Script Type:", NULL, NULL },
18898 12 { jwin_radio_proc, 40, 34+32, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear Missing (--) Slots", NULL, NULL },
18899 12 { jwin_radio_proc, 40, 34+80, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear All", NULL, NULL },
18900 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18901 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18902 };
18903
18904 void doClearSlots(byte* flags)
18905 {
18906 //{ Setup
18907 clearslots_dlg[0].dp2=get_zc_font(font_lfont);
18908 clearslots_dlg[3].d1 = get_selected_tab((TABPANEL*)assignscript_dlg[1].dp); //Default to current tab's type
18909 clearslots_dlg[4].flags |= D_SELECTED;
18910 clearslots_dlg[5].flags &= ~D_SELECTED;
18911 clearslots_dlg[6].flags &= ~D_SELECTED;
18912 if(((*flags) & SLOTMSGFLAG_MISSING) == 0)
18913 clearslots_dlg[5].flags |= D_DISABLED;
18914 else
18915 clearslots_dlg[5].flags &= ~D_DISABLED;
18916 //}
18917
18918 large_dialog(clearslots_dlg);
18919
18920 if(do_zqdialog(clearslots_dlg,2)==1)
18921 {
18922 int32_t q = 3;
18923 while((clearslots_dlg[++q].flags & D_SELECTED) == 0);
18924 switch(q)
18925 {
18926 case 4: //Clear type
18927 {
18928 clearAllSlots(clearslots_dlg[3].d1);
18929 break;
18930 }
18931 case 5: //Clear Missing
18932 {
18933 for(int32_t q = 0; q <= 10; ++q)
18934 clearAllSlots(q,SLOTMSGFLAG_MISSING);
18935 break;
18936 }
18937 case 6: //Clear ALL
18938 {
18939 for(int32_t q = 0; q <= 10; ++q)
18940 clearAllSlots(q);
18941 break;
18942 }
18943 }
18944 }
18945 }
18946
18947 static DIALOG exportzasm_dlg[] =
18948 {
18949 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Export ZASM", NULL, NULL },
18950 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
18951 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
18952 12 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
18953 12 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
18954 12 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
18955 12 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
18956 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18957 };
18958
18959 static DIALOG importzasm_dlg[] =
18960 {
18961 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import ZASM", NULL, NULL },
18962 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
18963 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
18964 12 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
18965 12 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
18966 // 5
18967 12 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
18968 12 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
18969 12 { jwin_text_proc, 50, 28+72, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Name:", NULL, NULL },
18970 12 { jwin_edit_proc, 50, 28+80, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 19, 0, NULL, NULL, NULL },
18971
18972 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18973 };
18974
18975 1 void center_zscript_dialogs()
18976 {
18977 1 jwin_center_dialog(exportzasm_dlg);
18978 1 jwin_center_dialog(importzasm_dlg);
18979 1 jwin_center_dialog(clearslots_dlg);
18980 1 }
18981
18982 // array of voices, one for each sfx sample in the data file
18983 // 0+ = voice #
18984 // -1 = voice not allocated
18985 int32_t sfx_voice[WAV_COUNT];
18986
18987 void Z_init_sound()
18988 {
18989 for(int32_t i=0; i<WAV_COUNT; i++)
18990 sfx_voice[i]=-1;
18991
18992 // master_volume(digi_volume,midi_volume);
18993 }
18994
18995 // returns number of voices currently allocated
18996 int32_t sfx_count()
18997 {
18998 int32_t c=0;
18999
19000 for(int32_t i=0; i<WAV_COUNT; i++)
19001 if(sfx_voice[i]!=-1)
19002 ++c;
19003
19004 return c;
19005 }
19006
19007 // clean up finished samples
19008 void sfx_cleanup()
19009 {
19010 for(int32_t i=0; i<WAV_COUNT; i++)
19011 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
19012 {
19013 deallocate_voice(sfx_voice[i]);
19014 sfx_voice[i]=-1;
19015 }
19016 }
19017
19018 bool sfx_templist = false;
19019 SAMPLE templist[WAV_COUNT];
19020 12 SAMPLE* sfx_get_sample(int32_t index)
19021 {
19022 // check index
19023
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if (index<=0 || index>=WAV_COUNT)
19024 return nullptr;
19025
19026
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (sfx_templist)
19027 {
19028 if (templist[index].data)
19029 return &templist[index];
19030 else return nullptr;
19031 }
19032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 else if (sfxdat)
19033 {
19034 if (index<Z35)
19035 {
19036 return (SAMPLE*)sfxdata[index].dat;
19037 }
19038 else
19039 {
19040 return (SAMPLE*)sfxdata[Z35].dat;
19041 }
19042 }
19043 else
19044 {
19045 12 return &customsfxdata[index];
19046 }
19047
19048 return nullptr;
19049 12 }
19050
19051 12 bool sfx_init(int32_t index)
19052 {
19053 // check index
19054
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if(index<1 || index>=WAV_COUNT)
19055 return false;
19056
19057
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(sfx_voice[index]==-1)
19058 {
19059 12 SAMPLE* sample = sfx_get_sample(index);
19060
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!sample)
19061 return false;
19062
19063 12 sfx_voice[index] = allocate_voice(sample);
19064 12 }
19065
19066 12 return sfx_voice[index] != -1;
19067 12 }
19068
19069 // plays an sfx sample
19070 12 void sfx(int32_t index,int32_t pan,bool loop,bool restart,zfix vol_perc,int32_t freq)
19071 {
19072
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!sfx_init(index))
19073 return;
19074
19075 12 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
19076 12 voice_set_pan(sfx_voice[index],pan);
19077
19078 12 int32_t pos = voice_get_position(sfx_voice[index]);
19079
19080 12 int temp_volume = (128 * (vol_perc / 100)).getFloor();
19081
19082
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(restart) voice_set_position(sfx_voice[index],0);
19083 12 voice_set_volume(sfx_voice[index], temp_volume);
19084
19085
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(pos<=0)
19086 12 voice_start(sfx_voice[index]);
19087 12 }
19088
19089 // start it (in loop mode) if it's not already playing,
19090 // otherwise just leave it in its current position
19091 void cont_sfx(int32_t index)
19092 {
19093 if(!sfx_init(index))
19094 return;
19095
19096 if(voice_get_position(sfx_voice[index])<=0)
19097 {
19098 voice_set_position(sfx_voice[index],0);
19099 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
19100 voice_start(sfx_voice[index]);
19101 }
19102 }
19103
19104 // adjust parameters while playing
19105 void adjust_sfx(int32_t index,int32_t pan,bool loop)
19106 {
19107 if(index<0 || index>=WAV_COUNT || sfx_voice[index]==-1)
19108 return;
19109
19110 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
19111 voice_set_pan(sfx_voice[index],pan);
19112 }
19113
19114 // pauses a voice
19115 void pause_sfx(int32_t index)
19116 {
19117 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
19118 voice_stop(sfx_voice[index]);
19119 }
19120
19121 // resumes a voice
19122 void resume_sfx(int32_t index)
19123 {
19124 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
19125 voice_start(sfx_voice[index]);
19126 }
19127
19128 // pauses all active voices
19129 void pause_all_sfx()
19130 {
19131 for(int32_t i=0; i<WAV_COUNT; i++)
19132 if(sfx_voice[i]!=-1)
19133 voice_stop(sfx_voice[i]);
19134 }
19135
19136 // resumes all paused voices
19137 void resume_all_sfx()
19138 {
19139 for(int32_t i=0; i<WAV_COUNT; i++)
19140 if(sfx_voice[i]!=-1)
19141 voice_start(sfx_voice[i]);
19142 }
19143
19144 // stops an sfx and deallocates the voice
19145 void stop_sfx(int32_t index)
19146 {
19147 if(index<0 || index>=WAV_COUNT)
19148 return;
19149
19150 if(sfx_voice[index]!=-1)
19151 {
19152 deallocate_voice(sfx_voice[index]);
19153 sfx_voice[index]=-1;
19154 }
19155 }
19156
19157 18 void kill_sfx()
19158 {
19159
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<WAV_COUNT; i++)
19160
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 1548 times.
6156 if(sfx_voice[i]!=-1)
19161 {
19162 1548 deallocate_voice(sfx_voice[i]);
19163 1548 sfx_voice[i]=-1;
19164 1548 }
19165 18 }
19166
19167 int32_t pan(int32_t x)
19168 {
19169 return 128;
19170 /*switch(pan_style)
19171 {
19172 case 0: return 128;
19173 case 1: return vbound((x>>1)+68,0,255);
19174 case 2: return vbound(((x*3)>>2)+36,0,255);
19175 }
19176 return vbound(x,0,255);*/
19177 }
19178
19179
19180 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2)
19181 {
19182 sfx1->bits = sfx2->bits;
19183 sfx1->stereo = sfx2->stereo;
19184 sfx1->freq = sfx2->freq;
19185 sfx1->priority = sfx2->priority;
19186 sfx1->len = sfx2->len;
19187 sfx1->loop_start = sfx2->loop_start;
19188 sfx1->loop_end = sfx2->loop_end;
19189 sfx1->param = sfx2->param;
19190
19191 if(sfx1->data != NULL)
19192 {
19193 free(sfx1->data);
19194 }
19195
19196 if(sfx2->data == NULL)
19197 sfx1->data = NULL;
19198 else
19199 {
19200 // When quests are saved and loaded, data is written in words.
19201 // If the last byte is dropped, it'll cause the sound to end with
19202 // a click. It could simply be extended and padded with 0, but
19203 // that causes compatibility issues... So we'll cut off
19204 // the last byte and decrease the length.
19205
19206 int32_t len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
19207
19208 while(len%sizeof(word))
19209 {
19210 // sizeof(word) should be 2, so this doesn't really need
19211 // to be a loop, but what the heck.
19212 sfx1->len--;
19213 len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
19214 }
19215
19216 sfx1->data = malloc(len);
19217 memcpy(sfx1->data, sfx2->data, len);
19218 }
19219 }
19220
19221 int32_t onSelectSFX()
19222 {
19223 SFXListerDialog(0).show();
19224 refresh(rMAP+rCOMBOS);
19225 return D_O_K;
19226 }
19227
19228 bool saveWAV(int32_t slot, const char *filename)
19229 {
19230 if (slot < 1 || slot >= 511 )
19231 return false;
19232
19233 if (customsfxdata[slot].data == NULL)
19234 return false;
19235
19236 std::ofstream ofs(filename, std::ios::binary);
19237 if (!ofs)
19238 return false;
19239 ofs.write("RIFF",4);
19240 uint32_t samplerate = customsfxdata[slot].freq;
19241 uint16_t channels = customsfxdata[slot].stereo ? 2 : 1;
19242 uint32_t datalen = customsfxdata[slot].len*channels*customsfxdata[slot].bits / 8;
19243 uint32_t size = 36 + datalen;
19244 ofs.write((char *)&size, 4);
19245 ofs.write("WAVE", 4);
19246 ofs.write("fmt ", 4);
19247 uint32_t fmtlen = 16;
19248 ofs.write((char *)&fmtlen, 4);
19249 uint16_t type = 1;
19250 ofs.write((char *)&type, 2);
19251 ofs.write((char *)&channels, 2);
19252 ofs.write((char *)&samplerate, 4);
19253 uint32_t bytespersec = samplerate*channels*customsfxdata[slot].bits / 8;
19254 ofs.write((char *)&bytespersec, 4);
19255 uint16_t blockalign = channels*customsfxdata[slot].bits / 8;
19256 ofs.write((char *)&blockalign, 2);
19257 uint16_t bitspersample = customsfxdata[slot].bits;
19258 ofs.write((char *)&bitspersample, 2);
19259 ofs.write("data", 4);
19260 ofs.write((char *)&datalen, 4);
19261 if (bitspersample == 8)
19262 {
19263 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
19264 {
19265 char data = ((char *)customsfxdata[slot].data)[i];
19266 data ^= 0x80;
19267 ofs.write(&data, 1);
19268 }
19269 }
19270 else if (bitspersample == 16)
19271 {
19272 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
19273 {
19274 uint16_t data = ((uint16_t *)customsfxdata[slot].data)[i];
19275 data ^= 0x8000;
19276 ofs.write((char *)&data, 2);
19277 }
19278 }
19279 else
19280 return false;
19281 return !!ofs;
19282 }
19283
19284 int32_t onMapStyles()
19285 {
19286 call_mapstyles_dialog();
19287 return D_O_K;
19288 }
19289
19290 int32_t d_misccolors_old_proc(int32_t msg,DIALOG *d,int32_t c)
19291 {
19292 //these are here to bypass compiler warnings about unused arguments
19293 c=c;
19294
19295 if(msg==MSG_DRAW)
19296 {
19297 textout_ex(screen,font,"0123456789ABCDEF",d->x+8,d->y,d->fg,d->bg);
19298 textout_ex(screen,font,"0",d->x,d->y+8,d->fg,d->bg);
19299 textout_ex(screen,font,"1",d->x,d->y+16,d->fg,d->bg);
19300 textout_ex(screen,font,"5",d->x,d->y+24,d->fg,d->bg);
19301
19302 for(int32_t i=0; i<32; i++)
19303 {
19304 int32_t px2 = d->x+((i&15)<<3)+8;
19305 int32_t py2 = d->y+((i>>4)<<3)+8;
19306 rectfill(screen,px2,py2,px2+7,py2+7,i);
19307 }
19308
19309 for(int32_t i=0; i<16; i++)
19310 {
19311 int32_t px2 = d->x+(i<<3)+8;
19312 rectfill(screen,px2,d->y+24,px2+7,d->y+31,i+80);
19313 }
19314 }
19315
19316 return D_O_K;
19317 }
19318
19319 int32_t hexclicked=-1;
19320
19321 int32_t d_misccolors_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
19322 {
19323 switch(msg)
19324 {
19325 case MSG_GOTFOCUS:
19326 hexclicked=((int32_t)(size_t)(d->dp3))+20;
19327 break;
19328
19329 case MSG_LOSTFOCUS:
19330 hexclicked=-1;
19331 break;
19332 }
19333
19334 return d_hexedit_proc(msg,d,c);
19335 }
19336
19337
19338 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c);
19339
19340 static int32_t misccolor1_list[] =
19341 {
19342 // dialog control number
19343 4, 5, 6, 7, 8, 20, 21, 22, 23, 24, 36, 37, 38, 39, 40, -1
19344 };
19345
19346 static int32_t misccolor2_list[] =
19347 {
19348 // dialog control number
19349 9, 10, 11, 12, 13, 25, 26, 27, 28, 29, 41, 42, 43, 44, 45, -1
19350 };
19351
19352 static int32_t misccolor3_list[] =
19353 {
19354 // dialog control number
19355 14, 15, 16, 17, 18, 30, 31, 32, 33, 34, 46, 47, 48, 49, 50, -1
19356 };
19357
19358 static int32_t misccolor4_list[] =
19359 {
19360 19, 35, 51, 54, 55, 56, -1
19361 };
19362
19363 static TABPANEL misccolor_tabs[] =
19364 {
19365 // (text)
19366 { (char *)"1", D_SELECTED, misccolor1_list, 0, NULL },
19367 { (char *)"2", 0, misccolor2_list, 0, NULL },
19368 { (char *)"3", 0, misccolor3_list, 0, NULL },
19369 { (char *)"4", 0, misccolor4_list, 0, NULL },
19370 { NULL, 0, NULL, 0, NULL }
19371 };
19372
19373 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c);
19374
19375 static DIALOG misccolors_dlg[] =
19376 {
19377 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
19378 12 { jwin_win_proc, 2, 21, 316, 197-23, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Misc Colors", NULL, NULL },
19379 // { jwin_frame_proc, 98-84+1+2, 52+8-6+4, 132, 100, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
19380 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
19381 12 { d_misccolors_proc, 92-84+1+2, 44+8-6+4, 128+8, 96+8, vc(9), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19382 //3
19383 12 { d_misccolors_tab_proc, 150+14-2+10-15, 60-14, 150-10+15, 144-20-10, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, (void *) misccolor_tabs, NULL, (void *)misccolors_dlg },
19384 //4
19385 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Text:", NULL, NULL },
19386 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Caption:", NULL, NULL },
19387 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Overworld Minmap:", NULL, NULL },
19388 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Background:", NULL, NULL },
19389 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 1:", NULL, NULL },
19390 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 2:", NULL, NULL },
19391 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Dark:", NULL, NULL },
19392 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Goal:", NULL, NULL },
19393 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Light):", NULL, NULL },
19394 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Dark):", NULL, NULL },
19395 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Background:", NULL, NULL },
19396 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Shadow:", NULL, NULL },
19397 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Triforce Frame:", NULL, NULL },
19398 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Background:", NULL, NULL },
19399 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Foreground:", NULL, NULL },
19400 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hero's Position:", NULL, NULL },
19401
19402 //20
19403 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)0, },
19404 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)1, },
19405 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)2, },
19406 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)3, },
19407 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)4, },
19408 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)5, },
19409 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)6, },
19410 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)7, },
19411 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)8, },
19412 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)9, },
19413 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)10, },
19414 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)11, },
19415 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)12, },
19416 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)13, },
19417 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)14, },
19418 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)15, },
19419
19420 //36
19421 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19422 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19423 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19424 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19425 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19426 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19427 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19428 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19429 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19430 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19431 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19432 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19433 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19434 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19435 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19436 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19437
19438 //52
19439 12 { jwin_button_proc, 90, 190-20, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
19440 12 { jwin_button_proc, 170, 190-20, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
19441 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Message Text:", NULL, NULL },
19442 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)35, },
19443 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
19444 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
19445 };
19446
19447 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c)
19448 {
19449
19450 switch(msg)
19451 {
19452 case MSG_WANTFOCUS:
19453 return D_WANTFOCUS;
19454 break;
19455 }
19456
19457 return jwin_tab_proc(msg,d,c);
19458 }
19459
19460
19461 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c)
19462 {
19463 //these are here to bypass compiler warnings about unused arguments
19464 c=c;
19465 int32_t mul=12;
19466
19467 switch(msg)
19468 {
19469 case MSG_CLICK:
19470 if(hexclicked!=-1)
19471 {
19472 int32_t color_col=vbound(((gui_mouse_x()-d->x-8)/mul),0,15);
19473 int32_t color_row=vbound(((gui_mouse_y()-d->y-10)/mul),0,11);
19474 sprintf((char*)misccolors_dlg[hexclicked].dp,"%X%X",color_row,color_col);
19475 object_message(misccolors_dlg+hexclicked,MSG_DRAW,0);
19476 }
19477
19478 break;
19479
19480 case MSG_DRAW:
19481 for(int32_t i=0; i<10; i++)
19482 {
19483 textprintf_centre_ex(screen,font,d->x+8+4+(i*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
19484 }
19485
19486 for(int32_t i=0; i<6; i++)
19487 {
19488 textprintf_centre_ex(screen,font,d->x+8+4+((10+i)*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
19489 }
19490
19491 for(int32_t i=0; i<10; i++)
19492 {
19493 textprintf_right_ex(screen,font,d->x+6,d->y+(i*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
19494 }
19495
19496 for(int32_t i=0; i<2; i++)
19497 {
19498 textprintf_right_ex(screen,font,d->x+6,d->y+((i+10)*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
19499 }
19500
19501 jwin_draw_frame(screen,d->x+6,d->y+8,int32_t(132*1.5)-2,int32_t(100*1.5)-2,FR_DEEP);
19502
19503 for(int32_t i=0; i<192; i++)
19504 {
19505 int32_t px2 = d->x+int32_t(((i&15)<<3)*1.5)+8;
19506 int32_t py2 = d->y+int32_t(((i>>4)<<3)*1.5)+8+2;
19507 rectfill(screen,px2,py2,px2+(mul-1),py2+(mul-1),i);
19508 }
19509
19510 break;
19511 }
19512
19513 return D_O_K;
19514 }
19515
19516
19517 int32_t onMiscColors()
19518 {
19519 char buf[17][3];
19520 byte *si = &(QMisc.colors.text);
19521 misccolors_dlg[0].dp2=get_zc_font(font_lfont);
19522
19523 for(int32_t i=0; i<16; i++)
19524 {
19525 sprintf(buf[i],"%02X",*(si++));
19526 sprintf(buf[16], "%02X", QMisc.colors.msgtext);
19527 misccolors_dlg[i+20].dp = buf[i];
19528 misccolors_dlg[55].dp = buf[16];
19529 }
19530
19531 large_dialog(misccolors_dlg);
19532
19533 if(do_zqdialog(misccolors_dlg,0)==52)
19534 {
19535 mark_save_dirty();
19536 si = &(QMisc.colors.text);
19537
19538 for(int32_t i=0; i<16; i++)
19539 {
19540 *si = zc_xtoi(buf[i]);
19541 ++si;
19542 }
19543
19544 QMisc.colors.msgtext = zc_xtoi(buf[16]);
19545 }
19546
19547 return D_O_K;
19548 }
19549
19550 // **** Palette cycling ****
19551
19552 static int32_t palclk[3];
19553 static int32_t palpos[3];
19554
19555 22 void reset_pal_cycling()
19556 {
19557
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 22 times.
88 for(int32_t i=0; i<3; i++)
19558 66 palclk[i]=palpos[i]=0;
19559 22 }
19560
19561 void cycle_palette()
19562 {
19563 if(!get_qr(qr_FADE))
19564 return;
19565
19566 int32_t level = Map.CurrScr()->color;
19567 bool refreshpal = false;
19568
19569 for(int32_t i=0; i<3; i++)
19570 {
19571 palcycle c = QMisc.cycles[level][i];
19572
19573 if(c.count&0xF0)
19574 {
19575 if(++palclk[i] >= c.speed)
19576 {
19577 palclk[i]=0;
19578
19579 if(++palpos[i] >= (c.count>>4))
19580 palpos[i]=0;
19581
19582 byte *si = colordata + CSET(level*pdLEVEL+poFADE1+1+palpos[i])*3;
19583
19584 si += (c.first&15)*3;
19585
19586 for(int32_t col=c.first&15; col<=(c.count&15); col++)
19587 {
19588 RAMpal[CSET(c.first>>4)+col] = _RGB(si);
19589 si+=3;
19590 }
19591
19592 refreshpal = true;
19593 }
19594 }
19595 }
19596
19597 if(refreshpal)
19598 {
19599 rebuild_trans_table();
19600 zc_set_palette_range(RAMpal,0,192,false);
19601 }
19602 }
19603
19604
19605 static void doHelp()
19606 {
19607 do_box_edit(helpstr, "ZQuest Help", true, true);
19608 }
19609
19610 int32_t onHelp()
19611 {
19612 restore_mouse();
19613 doHelp();
19614 return D_O_K;
19615 }
19616
19617 void doZstringshelp()
19618 {
19619 do_box_edit(zstringshelpstr, "ZStrings Help", true, true);
19620 }
19621
19622 int32_t onZstringshelp()
19623 {
19624 restore_mouse();
19625 doZstringshelp();
19626 return D_O_K;
19627 }
19628
19629 void call_layer_dialog(int map, int scr);
19630 int32_t onLayers()
19631 {
19632 call_layer_dialog(Map.getCurrMap(), Map.getCurrScr());
19633 if (CurrentLayer > 0 && Map.CurrScr()->layermap[CurrentLayer-1] == 0)
19634 CurrentLayer = 0;
19635 return D_O_K;
19636 }
19637
19638 void fps_callback()
19639 {
19640 lastfps=framecnt;
19641 framecnt=0;
19642 }
19643
19644 END_OF_FUNCTION(fps_callback)
19645
19646 //uint32_t col_diff[3*128];
19647 /*
19648 void bestfit_init(void)
19649 {
19650 int32_t i;
19651
19652 for (i=1; i<64; i++)
19653
19654 {
19655 int32_t k = i * i;
19656 col_diff[0 +i] = col_diff[0 +128-i] = k * (59 * 59);
19657 col_diff[128+i] = col_diff[128+128-i] = k * (30 * 30);
19658 col_diff[256+i] = col_diff[256+128-i] = k * (11 * 11);
19659 }
19660 }
19661 */
19662 void create_rgb_table2(RGB_MAP *table, AL_CONST PALETTE pal_8bit, void (*callback)(int32_t pos))
19663 {
19664 #define UNUSED 65535
19665 #define LAST 65532
19666
19667 // Allegro has been modified to use an 8 bit palette, but this method and RGB_MAP still use 6 bit.
19668 PALETTE pal;
19669 for (int i = 0; i < 256; i++)
19670 {
19671 pal[i] = pal_8bit[i];
19672 pal[i].r /= 4;
19673 pal[i].g /= 4;
19674 pal[i].b /= 4;
19675 }
19676
19677 /* macro add adds to single linked list */
19678 #define add(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
19679 (first != LAST ? (next[last] = (i)) : (first = (i))), \
19680 (last = (i))) : 0)
19681
19682 /* same but w/o checking for first element */
19683 #define add1(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
19684 next[last] = (i), \
19685 (last = (i))) : 0)
19686 /* calculates distance between two colors */
19687 #define dist(a1, a2, a3, b1, b2, b3) \
19688 (col_diff[ ((a2) - (b2)) & 0x7F] + \
19689 (col_diff + 128)[((a1) - (b1)) & 0x7F] + \
19690 (col_diff + 256)[((a3) - (b3)) & 0x7F])
19691
19692 /* converts r,g,b to position in array and back */
19693 #define pos(r, g, b) \
19694 (((r) / 2) * 32 * 32 + ((g) / 2) * 32 + ((b) / 2))
19695
19696 #define depos(pal, r, g, b) \
19697 ((b) = ((pal) & 31) * 2, \
19698 (g) = (((pal) >> 5) & 31) * 2, \
19699 (r) = (((pal) >> 10) & 31) * 2)
19700
19701 /* is current color better than pal1? */
19702 #define better(r1, g1, b1, pal1) \
19703 (((int32_t)dist((r1), (g1), (b1), \
19704 (pal1).r, (pal1).g, (pal1).b)) > (int32_t)dist2)
19705
19706 /* checking of position */
19707 #define dopos(rp, gp, bp, ts) \
19708 if ((rp > -1 || r > 0) && (rp < 1 || r < 61) && \
19709 (gp > -1 || g > 0) && (gp < 1 || g < 61) && \
19710 (bp > -1 || b > 0) && (bp < 1 || b < 61)) \
19711 { \
19712 i = first + rp * 32 * 32 + gp * 32 + bp; \
19713 if (!data[i]) \
19714 { \
19715 data[i] = val; \
19716 add1(i); \
19717 } \
19718 else if ((ts) && (data[i] != val)) \
19719 { \
19720 dist2 = (rp ? (col_diff+128)[(r+2*rp-pal[val].r) & 0x7F] : r2) + \
19721 (gp ? (col_diff )[(g+2*gp-pal[val].g) & 0x7F] : g2) + \
19722 (bp ? (col_diff+256)[(b+2*bp-pal[val].b) & 0x7F] : b2); \
19723 if (better((r+2*rp), (g+2*gp), (b+2*bp), pal[data[i]])) \
19724 { \
19725 data[i] = val; \
19726 add1(i); \
19727 } \
19728 } \
19729 }
19730
19731 int32_t i, curr, r, g, b, val, dist2;
19732 uint32_t r2, g2, b2;
19733 uint16_t next[32*32*32];
19734 uint8_t *data;
19735 int32_t first = LAST;
19736 int32_t last = LAST;
19737 int32_t count = 0;
19738 int32_t cbcount = 0;
19739
19740 #define AVERAGE_COUNT 18000
19741
19742 if(col_diff[1] == 0)
19743 bestfit_init();
19744
19745 memset(next, 255, sizeof(next));
19746 memset(table->data, 0, sizeof(char)*32*32*32);
19747
19748
19749 data = (uint8_t *)table->data;
19750
19751 /* add starting seeds for floodfill */
19752 for(i=1; i<PAL_SIZE; i++)
19753 {
19754 curr = pos(pal[i].r, pal[i].g, pal[i].b);
19755
19756 if(next[curr] == UNUSED)
19757 {
19758 data[curr] = i;
19759 add(curr);
19760 }
19761 }
19762
19763 /* main floodfill: two versions of loop for faster growing in blue axis */
19764 // while (first != LAST) {
19765 while(first < LAST)
19766 {
19767 depos(first, r, g, b);
19768
19769 /* calculate distance of current color */
19770 val = data[first];
19771 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
19772 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
19773 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
19774
19775 /* try to grow to all directions */
19776 #ifdef _MSC_VER
19777 #pragma warning(disable:4127)
19778 #endif
19779 dopos(0, 0, 1, 1);
19780 dopos(0, 0,-1, 1);
19781 dopos(1, 0, 0, 1);
19782 dopos(-1, 0, 0, 1);
19783 dopos(0, 1, 0, 1);
19784 dopos(0,-1, 0, 1);
19785 #ifdef _MSC_VER
19786 #pragma warning(default:4127)
19787 #endif
19788
19789 /* faster growing of blue direction */
19790 if((b > 0) && (data[first-1] == val))
19791 {
19792 b -= 2;
19793 first--;
19794 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
19795
19796 #ifdef _MSC_VER
19797 #pragma warning(disable:4127)
19798 #endif
19799 dopos(-1, 0, 0, 0);
19800 dopos(1, 0, 0, 0);
19801 dopos(0,-1, 0, 0);
19802 dopos(0, 1, 0, 0);
19803 #ifdef _MSC_VER
19804 #pragma warning(default:4127)
19805 #endif
19806
19807 first++;
19808 }
19809
19810 /* get next from list */
19811 i = first;
19812 first = next[first];
19813 next[i] = UNUSED;
19814
19815 /* second version of loop */
19816 // if (first != LAST) {
19817 if(first < LAST)
19818 {
19819
19820 depos(first, r, g, b);
19821
19822 val = data[first];
19823 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
19824 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
19825 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
19826
19827 #ifdef _MSC_VER
19828 #pragma warning(disable:4127)
19829 #endif
19830 dopos(0, 0, 1, 1);
19831 dopos(0, 0,-1, 1);
19832 dopos(1, 0, 0, 1);
19833 dopos(-1, 0, 0, 1);
19834 dopos(0, 1, 0, 1);
19835 dopos(0,-1, 0, 1);
19836 #ifdef _MSC_VER
19837 #pragma warning(default:4127)
19838 #endif
19839
19840 if((b < 61) && (data[first + 1] == val))
19841 {
19842 b += 2;
19843 first++;
19844 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7f];
19845 #ifdef _MSC_VER
19846 #pragma warning(disable:4127)
19847 #endif
19848 dopos(-1, 0, 0, 0);
19849 dopos(1, 0, 0, 0);
19850 dopos(0,-1, 0, 0);
19851 dopos(0, 1, 0, 0);
19852 #ifdef _MSC_VER
19853 #pragma warning(default:4127)
19854 #endif
19855
19856 first--;
19857 }
19858
19859 i = first;
19860 first = next[first];
19861 next[i] = UNUSED;
19862 }
19863
19864 count++;
19865
19866 if(count == (cbcount+1)*AVERAGE_COUNT/256)
19867 {
19868 if(cbcount < 256)
19869 {
19870 if(callback)
19871 callback(cbcount);
19872
19873 cbcount++;
19874 }
19875 }
19876
19877 }
19878
19879 /* only the transparent (pink) color can be mapped to index 0 */
19880 if((pal[0].r == 63) && (pal[0].g == 0) && (pal[0].b == 63))
19881 table->data[31][0][31] = 0;
19882
19883 if(callback)
19884 while(cbcount < 256)
19885 callback(cbcount++);
19886 }
19887
19888 11 void rebuild_trans_table()
19889 {
19890 11 refresh_rgb_tables();
19891 11 zq_rgb_table = rgb_table;
19892 11 }
19893
19894 int32_t isFullScreen()
19895 {
19896 return !is_windowed_mode();
19897 }
19898
19899 void hit_close_button()
19900 {
19901 close_button_quit=true;
19902 return;
19903 }
19904
19905 extern bool dirty_screen;
19906
19907 void anim_hw_screen()
19908 {
19909 ++cpoolbrush_index;
19910
19911 if(prv_mode)
19912 {
19913 if(Map.get_prvtime())
19914 {
19915 Map.set_prvtime(Map.get_prvtime()-1);
19916
19917 if(!Map.get_prvtime())
19918 {
19919 prv_warp=1;
19920 }
19921 }
19922 }
19923 if(AnimationOn)
19924 {
19925 animate_combos();
19926 update_freeform_combos();
19927 }
19928
19929 if(CycleOn)
19930 cycle_palette();
19931
19932 animate_coords();
19933 update_hw_screen();
19934 }
19935
19936 void custom_vsync()
19937 {
19938 anim_hw_screen();
19939 }
19940
19941 void switch_out()
19942 {
19943 zcmusic_pause(zcmusic, ZCM_PAUSE);
19944 zc_midi_pause();
19945 }
19946
19947 void switch_in()
19948 {
19949 if(exiting_program)
19950 return;
19951 zcmusic_pause(zcmusic, ZCM_RESUME);
19952 zc_midi_resume();
19953 }
19954
19955 void Z_eventlog(const char *format,...)
19956 {
19957 format=format; //to prevent a compiler warning
19958 }
19959
19960 int32_t get_currdmap()
19961 {
19962 return zinit.start_dmap;
19963 }
19964
19965 int32_t get_dlevel()
19966 {
19967 return DMaps[zinit.start_dmap].level;
19968 }
19969
19970 int32_t get_currscr()
19971 {
19972 return Map.getCurrScr();
19973 }
19974
19975 int32_t get_currmap()
19976 {
19977 return Map.getCurrMap();
19978 }
19979
19980 int32_t get_homescr()
19981 {
19982 return DMaps[zinit.start_dmap].cont;
19983 }
19984
19985 int get_screen_for_world_xy(int x, int y)
19986 {
19987 return -1;
19988 }
19989
19990 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
19991 {
19992 //TODO remove as special case?? -DD
19993 if(item_type==itype_shield)
19994 {
19995 return 2;
19996 }
19997
19998 int id = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
19999 return id > -1 ? itemsbuf[id].level : 0;
20000 }
20001
20002 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
20003 {
20004 if (game)
20005 {
20006 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
20007 return (result<0) ? 0 : itemsbuf[result].power;
20008 }
20009 return 1;
20010 }
20011
20012 int32_t current_item_id(int32_t itemtype, bool, bool, bool)
20013 {
20014 if (game)
20015 {
20016 int32_t result = -1;
20017 int32_t highestlevel = -1;
20018
20019 for (int32_t i = 0; i < MAXITEMS; i++)
20020 {
20021 if ((zq_ignore_item_ownership || game->get_item(i)) && itemsbuf[i].type == itemtype)
20022 {
20023 if (itemsbuf[i].level >= highestlevel)
20024 {
20025 highestlevel = itemsbuf[i].level;
20026 result = i;
20027 }
20028 }
20029 }
20030 return result;
20031 }
20032 for(int32_t i=0; i<MAXITEMS; i++)
20033 {
20034 if(itemsbuf[i].type==itemtype)
20035 return i;
20036 }
20037
20038 return -1;
20039 }
20040
20041
20042 bool can_use_item(int32_t item_type, int32_t item)
20043 {
20044 //these are here to bypass compiler warnings about unused arguments
20045 item_type=item_type;
20046 item=item;
20047
20048 return true;
20049 }
20050
20051 bool has_item(int32_t item_type, int32_t it)
20052 {
20053 //these are here to bypass compiler warnings about unused arguments
20054 item_type=item_type;
20055 it=it;
20056
20057 return true;
20058 }
20059
20060 int32_t get_bmaps(int32_t si)
20061 {
20062 //these are here to bypass compiler warnings about unused arguments
20063 si=si;
20064
20065 return 255;
20066 }
20067
20068 bool no_subscreen()
20069 {
20070 return false;
20071 }
20072
20073 12 static void allocate_crap()
20074 {
20075 12 filepath=(char*)malloc(2048);
20076 12 datapath=(char*)malloc(2048);
20077 12 midipath=(char*)malloc(2048);
20078 12 imagepath=(char*)malloc(2048);
20079 12 tmusicpath=(char*)malloc(2048);
20080 12 last_timed_save=(char*)malloc(2048);
20081
20082
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!filepath || !datapath || !imagepath || !midipath || !tmusicpath || !last_timed_save)
20083 {
20084 Z_error_fatal("Error: no memory for file paths!");
20085 }
20086
20087
20088 12 customtunes = (zctune*)malloc(sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
20089 12 memset(customtunes, 0, sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
20090
20091
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; ++i)
20092 {
20093 3072 customtunes[i].data=NULL;
20094 3072 }
20095
20096
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMTUNES; i++)
20097 {
20098 3024 midi_string[i+4]=customtunes[i].title;
20099 3024 screen_midi_string[i+5]=customtunes[i].title;
20100 3024 }
20101
20102
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<WAV_COUNT; i++)
20103 {
20104
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(sfx_string[i]!=NULL) delete sfx_string[i];
20105 3072 customsfxdata[i].data=NULL;
20106 3072 sfx_string[i] = new char[36];
20107 3072 memset(sfx_string[i], 0, 36);
20108 3072 }
20109
20110
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
20111 {
20112
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(weapon_string[i]!=NULL) delete weapon_string[i];
20113 3072 weapon_string[i] = new char[64];
20114 3072 memset(weapon_string[i], 0, 64);
20115 3072 }
20116
20117
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
20118 {
20119
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(item_string[i]!=NULL) delete item_string[i];
20120 3072 item_string[i] = new char[64];
20121 3072 memset(item_string[i], 0, 64);
20122 3072 }
20123
20124
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<eMAXGUYS; i++)
20125 {
20126
1/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6144 if(guy_string[i]!=NULL) delete guy_string[i];
20127 6144 guy_string[i] = new char[64];
20128 6144 memset(guy_string[i], 0, 64);
20129 6144 }
20130
20131
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
20132 {
20133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6144 times.
6144 delete ffscripts[i];
20134
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 ffscripts[i] = new script_data(ScriptType::FFC, i);
20135 6144 }
20136
20137
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
20138 {
20139
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete itemscripts[i];
20140
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 itemscripts[i] = new script_data(ScriptType::Item, i);
20141 3072 }
20142
20143
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
20144 {
20145
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete guyscripts[i];
20146
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 guyscripts[i] = new script_data(ScriptType::NPC, i);
20147 3072 }
20148
20149
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
20150 {
20151
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete screenscripts[i];
20152
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 screenscripts[i] = new script_data(ScriptType::Screen, i);
20153 3072 }
20154
20155
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
20156 {
20157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 delete globalscripts[i];
20158
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 globalscripts[i] = new script_data(ScriptType::Global, i);
20159 96 }
20160
20161
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
20162 {
20163
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 delete playerscripts[i];
20164
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 playerscripts[i] = new script_data(ScriptType::Hero, i);
20165 60 }
20166
20167
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
20168 {
20169
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete lwpnscripts[i];
20170
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 lwpnscripts[i] = new script_data(ScriptType::Lwpn, i);
20171 3072 }
20172
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
20173 {
20174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3072 times.
3072 delete ewpnscripts[i];
20175
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 ewpnscripts[i] = new script_data(ScriptType::Ewpn, i);
20176 3072 }
20177
20178
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
20179 {
20180
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete dmapscripts[i];
20181
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 dmapscripts[i] = new script_data(ScriptType::DMap, i);
20182 3072 }
20183
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
20184 {
20185
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete itemspritescripts[i];
20186
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 itemspritescripts[i] = new script_data(ScriptType::ItemSprite, i);
20187 3072 }
20188
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
20189 {
20190
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 delete comboscripts[i];
20191
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 comboscripts[i] = new script_data(ScriptType::Combo, i);
20192 6144 }
20193
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
20194 {
20195
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 delete genericscripts[i];
20196
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 genericscripts[i] = new script_data(ScriptType::Generic, i);
20197 6144 }
20198
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
20199 {
20200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3072 times.
3072 delete subscreenscripts[i];
20201
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 subscreenscripts[i] = new script_data(ScriptType::EngineSubscreen, i);
20202 3072 }
20203 12 }
20204
20205 static void handle_sentry_tags()
20206 {
20207 static bool sentry_first_time = true;
20208
20209 static MapCursor sentry_last_map_cursor;
20210 if (Map.getCursor() != sentry_last_map_cursor || sentry_first_time)
20211 {
20212 sentry_last_map_cursor = Map.getCursor();
20213 zapp_reporting_set_tag("cursor.map", sentry_last_map_cursor.map);
20214 zapp_reporting_set_tag("cursor.screen", sentry_last_map_cursor.screen);
20215 zapp_reporting_set_tag("cursor.viewscr", sentry_last_map_cursor.viewscr);
20216 zapp_reporting_set_tag("cursor.size", sentry_last_map_cursor.size);
20217 }
20218
20219 static bool sentry_last_is_compact;
20220 if (is_compact != sentry_last_is_compact || sentry_first_time)
20221 {
20222 sentry_last_is_compact = is_compact;
20223 zapp_reporting_set_tag("compact", sentry_last_is_compact);
20224 }
20225
20226 sentry_first_time = false;
20227 }
20228
20229 int32_t Awpn=-1, Bwpn=-1, Xwpn = -1, Ywpn = -1;
20230 84 sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations, portals;
20231 int32_t exittimer = 10000, exittimer2 = 100;
20232
20233 template <typename ...Params>
20234 [[noreturn]] void FatalConsole(const char *format, Params&&... params)
20235 {
20236 FFCore.ZScriptConsole(CConsoleLoggerEx::COLOR_RED|CConsoleLoggerEx::COLOR_INTENSITY|CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"");
20237 Z_error_fatal(format, std::forward<Params>(params)...);
20238 }
20239
20240 5 static BITMAP* load_asset_bmp(const char* path)
20241 {
20242 5 BITMAP* bmp = load_bmp(path, nullptr);
20243
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (!bmp)
20244 Z_error_fatal("Failed to load required asset: %s\n", path);
20245 5 return bmp;
20246 }
20247
20248 1 static void load_asset_pal(PALETTE pal, const char* path)
20249 {
20250 1 BITMAP* bmp = load_bmp(path, pal);
20251
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!bmp)
20252 Z_error_fatal("Failed to load required asset: %s\n", path);
20253 1 }
20254
20255 1 static MIDI* load_asset_midi(const char* path)
20256 {
20257 1 MIDI* midi = load_midi(path);
20258
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!midi)
20259 Z_error_fatal("Failed to load required asset: %s\n", path);
20260 1 return midi;
20261 }
20262
20263 BITMAP* asset_icons_bmp;
20264 BITMAP* asset_engravings_bmp;
20265 BITMAP* asset_mouse_bmp;
20266 BITMAP* asset_select_bmp;
20267 BITMAP* asset_arrows_bmp;
20268 MIDI* asset_tunes_midi;
20269 PALETTE asset_pal;
20270
20271 1 static void load_assets()
20272 {
20273 1 asset_icons_bmp = load_asset_bmp("assets/editor/icons.bmp");
20274 1 asset_engravings_bmp = load_asset_bmp("assets/editor/engravings.bmp");
20275 1 asset_mouse_bmp = load_asset_bmp("assets/editor/mouse.bmp");
20276 1 asset_select_bmp = load_asset_bmp("assets/editor/select.bmp");
20277 1 asset_arrows_bmp = load_asset_bmp("assets/editor/arrows.bmp");
20278 1 asset_tunes_midi = load_asset_midi("assets/editor/tunes.mid");
20279 1 load_asset_pal(asset_pal, "assets/editor/pal.bmp");
20280 1 }
20281
20282 static bool application_has_loaded;
20283
20284 void do_dev_qrs_zscript_command(string const& fname);
20285
20286 1 int32_t main(int32_t argc,char **argv)
20287 {
20288
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (used_switch(argc, argv, "-test-zc"))
20289 1 set_headless_mode();
20290
20291 1 zalleg_setup_allegro(App::zquest, argc, argv);
20292 1 allocate_crap();
20293
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_should_zprint_cb([]() {
20294 return get_qr(qr_SCRIPTERRLOG) || DEVLEVEL > 0;
20295 });
20296
20297 1 Z_title("ZQuest Classic Editor, %s", getVersionString());
20298
20299
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!get_qst_buffers())
20300 {
20301 Z_error_fatal("Error");
20302 }
20303
20304 1 undocombobuf.clear();
20305 1 undocombobuf.resize(MAXCOMBOS);
20306
20307
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if((newundotilebuf=(tiledata*)malloc(NEWMAXTILES*sizeof(tiledata)))==NULL)
20308 {
20309 Z_error_fatal("Error: no memory for tile undo buffer!");
20310 }
20311
20312 1 memset(newundotilebuf, 0, NEWMAXTILES*sizeof(tiledata));
20313 1 newtilebuf = (tiledata*)malloc(NEWMAXTILES*sizeof(tiledata));
20314
20315
2/2
✓ Branch 0 taken 2574000 times.
✓ Branch 1 taken 1 times.
2574001 for(int32_t j=0; j<NEWMAXTILES; j++)
20316 2574000 newtilebuf[j].data=NULL;
20317
20318 1 zc_srand(time(0));
20319
20320 1 zeditor_handle_commands();
20321
20322 1 three_finger_flag=false;
20323
20324 #ifndef __EMSCRIPTEN__
20325
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(zc_get_config("zquest","open_debug_console",0))
20326 initConsole();
20327 #endif
20328
20329 LOCK_VARIABLE(lastfps);
20330
20331 LOCK_VARIABLE(framecnt);
20332 LOCK_FUNCTION(fps_callback);
20333
20334
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
20335 {
20336 Z_error_fatal("couldn't allocate timer");
20337 }
20338
20339
20340 LOCK_VARIABLE(dclick_status);
20341 LOCK_VARIABLE(dclick_time);
20342 1 lock_dclick_function();
20343 1 install_int(dclick_check, 20);
20344
20345 1 set_gfx_mode(GFX_TEXT,80,50,0,0);
20346
20347 1 load_assets();
20348
20349 1 Z_message("OK\n");
20350
20351
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 helpstr = util::read_text_file("docs/zquest.txt");
20352
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 zstringshelpstr = util::read_text_file("docs/zstrings.txt");
20353
20354 // loading data files...
20355
20356 1 filepath[0]=temppath[0]=0;
20357
20358 1 const char *default_path="";
20359
20360 1 strcpy(datapath,zc_get_config("zquest",data_path_name,default_path));
20361 1 strcpy(midipath,zc_get_config("zquest",midi_path_name,default_path));
20362 1 strcpy(imagepath,zc_get_config("zquest",image_path_name,default_path));
20363 1 strcpy(tmusicpath,zc_get_config("zquest",tmusic_path_name,default_path));
20364 1 chop_path(datapath);
20365 1 chop_path(midipath);
20366 1 chop_path(imagepath);
20367 1 chop_path(tmusicpath);
20368
20369 1 DisableLPalShortcuts = zc_get_config("zquest","dis_lpal_shortcut",1);
20370 1 DisableCompileConsole = zc_get_config("zquest","internal_compile_console",0);
20371 1 MouseScroll = zc_get_config("zquest","mouse_scroll",0);
20372 1 MMapCursorStyle = zc_get_config("zquest","cursorblink_style",1);
20373 1 LayerDitherBG = zc_get_config("zquest", "layer_dither_bg", -1);
20374 1 LayerDitherSz = zc_get_config("zquest", "layer_dither_sz", 3);
20375 1 InvalidBG = zc_get_config("zquest", "invalid_bg", 0);
20376 1 TileProtection = zc_get_config("zquest","tile_protection",1);
20377 1 ComboProtection = zc_get_config("zquest","combo_protection",TileProtection);
20378 1 ShowGrid = zc_get_config("zquest","show_grid",0);
20379 1 ShowCurScreenOutline = zc_get_config("zquest","show_current_screen_outline",1);
20380 1 ShowScreenGrid = zc_get_config("zquest","show_screen_grid",0);
20381 1 ShowRegionGrid = zc_get_config("zquest","show_region_grid",1);
20382 1 HighQualityScreenRendering = zc_get_config("zquest","high_quality_screen_rendering",1);
20383 1 GridColor = zc_get_config("zquest","grid_color",15);
20384 1 CmbCursorCol = zc_get_config("zquest","combo_cursor_color",15);
20385 1 TilePgCursorCol = zc_get_config("zquest","tpage_cursor_color",15);
20386 1 CmbPgCursorCol = zc_get_config("zquest","cpage_cursor_color",15);
20387 1 TTipHLCol = zc_get_config("zquest","ttip_hl_color",13);
20388 1 CheckerCol1 = zc_get_config("zquest","checker_color_1",7);
20389 1 CheckerCol2 = zc_get_config("zquest","checker_color_2",8);
20390 1 SnapshotFormat = zc_get_config("zquest","snapshot_format",3);
20391 1 SnapshotScale = zc_get_config("zquest","snapshot_scale",2);
20392 1 SavePaths = zc_get_config("zquest","save_paths",1);
20393 1 CycleOn = zc_get_config("zquest","cycle_on",1);
20394 1 ShowFPS = zc_get_config("zquest","showfps",0)!=0;
20395 1 SaveDragResize = zc_get_config("zquest","save_drag_resize",0)!=0;
20396 1 DragAspect = zc_get_config("zquest","drag_aspect",0)!=0;
20397 1 SaveWinPos = zc_get_config("zquest","save_window_position",0)!=0;
20398 1 ComboBrush = zc_get_config("zquest","combo_brush",0);
20399 1 FloatBrush = zc_get_config("zquest","float_brush",0);
20400 1 AutoBrush = zc_get_config("zquest","autobrush",1);
20401 1 LinkedScroll = zc_get_config("zquest","linked_comboscroll",0);
20402 1 allowHideMouse = zc_get_config("ZQ_GUI","allowHideMouse",0);
20403 1 ShowFavoriteComboModes = zc_get_config("ZQ_GUI","show_fav_combo_modes",1);
20404 1 NoHighlightLayer0 = zc_get_config("zquest","no_highlight_layer0",0);
20405 1 RulesetDialog = zc_get_config("zquest","rulesetdialog",1);
20406 1 EnableTooltips = zc_get_config("zquest","enable_tooltips",1);
20407 1 TooltipsHighlight = zc_get_config("zquest","ttip_highlight",1);
20408 1 tooltip_maxtimer = vbound(zc_get_config("zquest","ttip_timer",30),0,60*60);
20409 1 ShowFFScripts = zc_get_config("zquest","showffscripts",1);
20410 1 ShowSquares = zc_get_config("zquest","showsquares",1);
20411 1 ShowFFCs = zc_get_config("zquest","showffcs",0);
20412 1 ShowInfo = zc_get_config("zquest","showinfo",1);
20413 1 skipLayerWarning = zc_get_config("zquest","skip_layer_warning",0);
20414 1 numericalFlags = zc_get_config("zquest","numerical_flags",0);
20415 1 ViewLayer2BG = zc_get_config("zquest","layer2_bg",0);
20416 1 ViewLayer3BG = zc_get_config("zquest","layer3_bg",0);
20417 1 ActiveLayerHighlight = zc_get_config("zquest","hl_active_lyr",0);
20418 1 DragCenterOfSquares = zc_get_config("zquest","drag_squares_from_center",0);
20419 1 SmartFFCPlacement = zc_get_config("zquest","smart_ffc_placement",0);
20420
20421 1 OpenLastQuest = zc_get_config("zquest","open_last_quest",0);
20422 1 ShowMisalignments = zc_get_config("zquest","show_misalignments",0);
20423 1 AnimationOn = zc_get_config("zquest","animation_on",1);
20424 1 AutoBackupRetention = zc_get_config("zquest","auto_backup_retention",2);
20425 1 AutoSaveInterval = zc_get_config("zquest","auto_save_interval",6);
20426 1 AutoSaveRetention = zc_get_config("zquest","auto_save_retention",2);
20427 1 UncompressedAutoSaves = zc_get_config("zquest","uncompressed_auto_saves",1);
20428 1 OverwriteProtection = zc_get_config("zquest","overwrite_prevention",0)!=0;
20429 1 ImportMapBias = zc_get_config("zquest","import_map_bias",0);
20430
20431 1 KeyboardRepeatDelay = zc_get_config("zquest","keyboard_repeat_delay",300);
20432 1 KeyboardRepeatRate = zc_get_config("zquest","keyboard_repeat_rate",80);
20433
20434 // Frameskip = zc_get_config("zquest","frameskip",0); //todo: this is not actually supported yet.
20435 1 RequestedFPS = zc_get_config("zquest","fps",60);
20436
20437 // Autofill for Combo Page, Tile Page
20438 1 PreFillTileEditorPage = zc_get_config("zquest","PreFillTileEditorPage",0);
20439 1 PreFillComboEditorPage = zc_get_config("zquest","PreFillComboEditorPage",0);
20440
20441 1 pixeldb = zc_get_config("ZQ_GUI","bottom_8_pixels",0);
20442 1 infobg = zc_get_config("ZQ_GUI","info_text_bg",0);
20443
20444 1 large_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_large",0);
20445 1 compact_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_compact",1);
20446
20447 1 compact_square_panels = zc_get_config("ZQ_GUI","square_panels_compact",0);
20448
20449 1 large_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_large",0);
20450 1 compact_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_compact",1);
20451 1 large_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_large",1);
20452 1 compact_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_compact",1);
20453
20454
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(zc_get_config("gui","disable_window_resizing",0))
20455 all_set_resize_flag(false);
20456
20457 1 load_hotkeys();
20458
20459 #ifdef _WIN32
20460 zqUseWin32Proc = zc_get_config("zquest","zq_win_proc_fix",0);
20461
20462 #endif
20463
20464
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!render_timer_start())
20465 {
20466 Z_error_fatal("couldn't allocate timer");
20467 }
20468
20469 1 byte layermask = zc_get_config("zquest","layer_mask",0x7F);
20470 1 int32_t usefullscreen = zc_get_config("zquest","fullscreen",0);
20471 1 tempmode = (usefullscreen == 0 ? GFX_AUTODETECT_WINDOWED : GFX_AUTODETECT_FULLSCREEN);
20472
20473
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 for(int32_t x=0; x<7; x++)
20474 {
20475 7 LayerMaskInt[x]=get_bit(&layermask,x);
20476 7 }
20477
20478 1 DuplicateAction[0] = zc_get_config("zquest","normal_duplicate_action",2);
20479 1 DuplicateAction[1] = zc_get_config("zquest","horizontal_duplicate_action",0);
20480 1 DuplicateAction[2] = zc_get_config("zquest","vertical_duplicate_action",0);
20481 1 DuplicateAction[3] = zc_get_config("zquest","both_duplicate_action",0);
20482 1 LeechUpdate = zc_get_config("zquest","leech_update",500);
20483 1 LeechUpdateTiles = zc_get_config("zquest","leech_update_tiles",1);
20484 1 OnlyCheckNewTilesForDuplicates = zc_get_config("zquest","only_check_new_tiles_for_duplicates",0);
20485 //gui_colorset = zc_get_config("zquest","gui_colorset",0);
20486
20487 1 strcpy(last_timed_save,zc_get_config("zquest","last_timed_save",""));
20488
20489 1 midi_volume = zc_get_config("zquest", "midi", 255);
20490
20491 1 abc_patternmatch = zc_get_config("zquest", "lister_pattern_matching", 1);
20492 1 NoScreenPreview = zc_get_config("zquest", "no_preview", 0);
20493
20494 1 monochrome_console = zc_get_config("CONSOLE","monochrome_debuggers",0)?1:0;
20495
20496 1 try_recovering_missing_scripts = 0;//zc_get_config("Compiler", "try_recovering_missing_scripts",0);
20497 //We need to remove all of the zeldadx refs to the config file for zquest.
20498
20499 1 set_keyboard_rate(KeyboardRepeatDelay,KeyboardRepeatRate);
20500
20501 1 is_compact = zc_get_config("ZQ_GUI","compact_mode",1);
20502 1 mapscreenbmp = nullptr;
20503 1 brushbmp = nullptr;
20504 1 brushscreen = nullptr;
20505 1 screen2 = nullptr;
20506
20507
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 1 times.
1261 for(int32_t i=0; i<MAXFAVORITECOMBOS; ++i)
20508 {
20509 1260 favorite_combos[i]=-1;
20510 1260 }
20511 1 FavoriteComboPage = 0;
20512
20513
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(used_switch(argc,argv,"-d"))
20514 {
20515 set_debug(!strcmp(zquestpwd,zc_get_config("zquest","debug_this","")));
20516 }
20517
20518 1 zcmusic_init();
20519 1 zcmixer = zcmixer_create();
20520 24 install_int_ex([](){ zcmusic_poll(); }, MSEC_TO_TIMER(25));
20521
20522 1 set_color_depth(8);
20523
20524 1 set_close_button_callback((void (*)()) hit_close_button);
20525
20526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(used_switch(argc,argv,"-fullscreen"))
20527 {
20528 tempmode = GFX_AUTODETECT_FULLSCREEN;
20529 }
20530
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 else if(used_switch(argc,argv,"-windowed"))
20531 {
20532 tempmode=GFX_AUTODETECT_WINDOWED;
20533 }
20534
20535 1 zq_screen_w = LARGE_W;
20536 1 zq_screen_h = LARGE_H;
20537 1 window_width = zc_get_config("zquest","window_width",-1);
20538 1 window_height = zc_get_config("zquest","window_height",-1);
20539 1 auto [w, h] = zc_get_default_display_size(LARGE_W, LARGE_H, window_width, window_height);
20540
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 int32_t videofail = is_headless() ? 0 : (set_gfx_mode(tempmode,w,h,zq_screen_w,zq_screen_h));
20541
20542 //extra block here is intentional
20543
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(videofail!=0)
20544 {
20545 quit_game();
20546 allegro_exit();
20547 }
20548
20549 1 zalleg_create_window();
20550 1 Z_message("gfx mode set at -%d %dbpp %d x %d \n",
20551 1 tempmode, get_color_depth(), zq_screen_w, zq_screen_h);
20552
20553 1 set_window_title("ZC Editor");
20554
20555 1 load_size_poses();
20556
20557
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!is_headless())
20558 {
20559 // Just in case.
20560 while (!all_get_display()) {
20561 al_rest(1);
20562 }
20563
20564 al_resize_display(all_get_display(), w, h);
20565 }
20566
20567
20568 #ifndef __EMSCRIPTEN__
20569
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!all_get_fullscreen_flag() && !is_headless()) {
20570 al_resize_display(all_get_display(), w, h);
20571
20572 int window_w = al_get_display_width(all_get_display());
20573 int window_h = al_get_display_height(all_get_display());
20574
20575 int new_x = zc_get_config("zquest","window_x",0);
20576 int new_y = zc_get_config("zquest","window_y",0);
20577 if(zc_get_config("zquest","save_window_position",0) && (new_x || new_y))
20578 {
20579 //load saved position
20580 //already stored in new_x/new_y
20581 }
20582 else
20583 {
20584 //Get default position
20585 ALLEGRO_MONITOR_INFO info;
20586 al_get_monitor_info(0, &info);
20587
20588 int mw = (info.x2 - info.x1);
20589 int mh = (info.y2 - info.y1);
20590 new_x = mw / 2 - window_w / 2;
20591 new_y = mh / 2 - window_h / 2;
20592 //Don't spawn the window too far down (taskbar?)
20593 if(new_y + window_h > mh - 72)
20594 new_y = mh-72-window_h;
20595 }
20596 #ifdef ALLEGRO_MACOSX
20597 if (zc_get_config("zquest","save_window_position",0))
20598 al_set_window_position(all_get_display(), new_x, new_y);
20599 #else
20600 al_set_window_position(all_get_display(), new_x, new_y);
20601 #endif
20602 }
20603 #endif
20604
20605 1 position_mouse(zq_screen_w/2,zq_screen_h/2);
20606
20607 1 dmapbmp_small = create_bitmap_ex(8,65,33);
20608 1 dmapbmp_large = create_bitmap_ex(8,177,81);
20609
20610
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!screen2 || !dmapbmp_large || !dmapbmp_large || !brushbmp || !brushscreen)// || !brushshadowbmp )
20611 {
20612 Z_error_fatal("Failed to create system bitmaps!\n");
20613 return 1;
20614 }
20615
20616
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!is_headless())
20617 {
20618 zc_set_palette(asset_pal);
20619 get_palette(RAMpal);
20620 load_colorset(gui_colorset);
20621 zc_set_palette(RAMpal);
20622 clear_to_color(screen,vc(0));
20623 }
20624
20625 1 zScript = string();
20626 1 strcpy(zScriptBytes, "0 Bytes in Buffer");
20627
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
13 for(int32_t i=0; i<MOUSE_BMP_MAX; i++)
20628 {
20629
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t j=0; j<4; j++)
20630 {
20631 48 mouse_bmp[i][j] = NULL;
20632 48 mouse_bmp_1x[i][j] = NULL;
20633 48 }
20634 12 }
20635 1 load_mice();
20636 1 gui_mouse_focus=0;
20637 1 MouseSprite::set(ZQM_NORMAL);
20638 1 render_zq(); // Ensure the rendering bitmaps are setup.
20639
20640 #ifdef __EMSCRIPTEN__
20641 em_mark_ready_status();
20642 #endif
20643
20644 1 load_icons();
20645
20646 1 bool load_last_timed_save=false;
20647
20648 1 load_recent_quests();
20649 1 refresh_recent_menu();
20650 //clearConsole();
20651
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 if((last_timed_save[0]!=0)&&(exists(last_timed_save)))
20652 {
20653 if (alert_confirm("ZQuest","It appears that ZQuest crashed last time.\nWould you like to load the last timed save?"))
20654 {
20655 int32_t ret = load_quest(last_timed_save);
20656
20657 if(ret == qe_OK)
20658 {
20659 strcpy(filepath,last_timed_save);
20660 load_last_timed_save=true;
20661 mark_save_dirty();
20662 }
20663 else
20664 {
20665 displayinfo("Error","Unable to reload the last timed save.");
20666 }
20667 }
20668 }
20669
20670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(!load_last_timed_save)
20671 {
20672 1 strcpy(filepath,zc_get_config("zquest",last_quest_name,""));
20673
20674
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if(argc>1 && argv[1][0]!='-')
20675 {
20676 int32_t ret = load_quest(argv[1]);
20677
20678 if(ret == qe_OK)
20679 {
20680 first_save=true;
20681 strcpy(filepath,argv[1]);
20682 refresh(rALL);
20683 }
20684 }
20685
2/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 else if(OpenLastQuest&&filepath[0]&&exists(filepath)&&!used_switch(argc,argv,"-new"))
20686 {
20687 int32_t ret = load_quest(filepath);
20688
20689 if(ret == qe_OK)
20690 {
20691 first_save=true;
20692 refresh(rALL);
20693 }
20694 else
20695 {
20696 filepath[0]=temppath[0]=0;
20697 first_save=false;
20698 }
20699 }
20700 else
20701 {
20702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (onNew() == D_CLOSE)
20703 {
20704 1 Z_message("User canceled creating new quest, closing.\n");
20705 1 exit(0);
20706 }
20707
20708 //otherwise the blank quest gets the name of the last loaded quest... not good! -DD
20709 filepath[0]=temppath[0]=0;
20710 first_save=false;
20711 }
20712 }
20713
20714 if(used_switch(argc,argv,"-q"))
20715 {
20716 Z_message("-q switch used, quitting program.\n");
20717 zq_exit(0);
20718 }
20719
20720 for(int32_t x=0; x<MAXITEMS; x++)
20721 {
20722 lens_hint_item[x][0]=0;
20723 lens_hint_item[x][1]=0;
20724 }
20725
20726 for(int32_t x=0; x<MAXWPNS; x++)
20727 {
20728 lens_hint_weapon[x][0]=0;
20729 lens_hint_weapon[x][1]=0;
20730 }
20731
20732 load_selections();
20733 load_arrows();
20734 DIALOG_PLAYER *player2=init_dialog(dialogs,-1);
20735
20736 get_palette(RAMpal);
20737
20738 rgb_map = zq_rgb_table;
20739
20740 #ifdef __EMSCRIPTEN__
20741 {
20742 int qs_map = EM_ASM_INT({
20743 return new URL(location.href).searchParams.get('map') ?? -1;
20744 });
20745 int qs_screen = EM_ASM_INT({
20746 return new URL(location.href).searchParams.get('screen') ?? -1;
20747 });
20748 if (qs_map != -1 && qs_screen != -1) {
20749 Map.setCurrMap(qs_map);
20750 Map.setCurrScr(qs_screen);
20751 }
20752 }
20753 #endif
20754
20755 // setup_combo_animations();
20756 pause_refresh = false;
20757 refresh_pal();
20758 refresh(rALL);
20759 for(int q = 0; q < brush_width_menu.size(); ++q)
20760 brush_width_menu.at(q)->select(q==0);
20761 for(int q = 0; q < brush_height_menu.size(); ++q)
20762 brush_height_menu.at(q)->select(q==0);
20763 set_filltype(1);
20764
20765 rebuild_trans_table();
20766
20767 if (!is_headless())
20768 {
20769 set_display_switch_mode(SWITCH_BACKGROUND);
20770 set_display_switch_callback(SWITCH_OUT, switch_out);
20771 set_display_switch_callback(SWITCH_IN, switch_in);
20772 }
20773
20774 if(!update_dialog(player2))
20775 exiting_program = true;
20776 //clear_keybuf();
20777 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
20778 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
20779
20780 fix_drawing_mode_menu();
20781
20782
20783 #ifdef _WIN32
20784
20785 if(zqUseWin32Proc != FALSE)
20786 {
20787 al_trace("Config file warning: \"zq_win_proc_fix\" enabled switch found. This can cause crashes on some computers.\n");
20788 win32data.zqSetDefaultThreadPriority(0);
20789 win32data.zqSetCustomCallbackProc(al_get_win_window_handle(all_get_display()));
20790 }
20791
20792 #endif
20793
20794 time(&auto_save_time_start);
20795
20796 FFCore.init();
20797 ZQincludePaths = FFCore.includePaths;
20798
20799 Map.setCopyFFC(-1); //Do not have an initial ffc on the clipboard.
20800 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
20801 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
20802 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
20803 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
20804 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
20805
20806 application_has_loaded = true;
20807
20808 while(!exiting_program)
20809 {
20810 handle_sentry_tags();
20811
20812 #ifdef _WIN32
20813 if(zqUseWin32Proc != FALSE)
20814 win32data.Update(Frameskip); //experimental win32 fixes
20815 #endif
20816 check_autosave();
20817 ++alignment_arrow_timer;
20818
20819 if(alignment_arrow_timer>63)
20820 {
20821 alignment_arrow_timer=0;
20822 }
20823 ++frame;
20824
20825 file_menu.disable_uid(MENUID_FILE_SAVE, saved||disable_saving||OverwriteProtection);
20826 file_menu.disable_uid(MENUID_FILE_REVERT, saved||disable_saving||OverwriteProtection);
20827 file_menu.disable_uid(MENUID_FILE_SAVEAS, disable_saving);
20828
20829 fixtools_menu.disable_uid(MENUID_FIXTOOL_OLDSTRING,
20830 !(get_qr(qr_OLD_STRING_EDITOR_MARGINS)
20831 ||get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT)));
20832
20833 edit_menu.disable_uid(MENUID_EDIT_UNDO, !Map.CanUndo());
20834 edit_menu.disable_uid(MENUID_EDIT_REDO, !Map.CanRedo());
20835
20836 bool canpaste = Map.CanPaste();
20837 edit_menu.disable_uid(MENUID_EDIT_PASTE, !canpaste);
20838 edit_menu.disable_uid(MENUID_EDIT_PASTEALL, !canpaste);
20839 edit_menu.disable_uid(MENUID_EDIT_ADVPASTE, !canpaste);
20840 edit_menu.disable_uid(MENUID_EDIT_SPECPASTE, !canpaste);
20841 rc_menu_screen.disable_uid(MENUID_RCSCREEN_PASTE, !canpaste);
20842 rc_menu_screen.disable_uid(MENUID_RCSCREEN_ADVPASTE, !canpaste);
20843 rc_menu_screen.disable_uid(MENUID_RCSCREEN_SPECPASTE, !canpaste);
20844 for(MenuItem& mit : paste_menu.inner())
20845 mit.disable(!canpaste);
20846 for(MenuItem& mit : paste_item_menu.inner())
20847 mit.disable(!canpaste);
20848
20849 edit_menu.disable_uid(MENUID_EDIT_COPY, !(Map.CurrScr()->valid&mVALID));
20850 edit_menu.disable_uid(MENUID_EDIT_DELETE, !(Map.CurrScr()->valid&mVALID));
20851
20852 // Are some things selected?
20853 view_menu.select_uid(MENUID_VIEW_WALKABILITY, Flags&cWALK);
20854 view_menu.select_uid(MENUID_VIEW_FLAGS, Flags&cFLAGS);
20855 view_menu.select_uid(MENUID_VIEW_CSET, Flags&cCSET);
20856 view_menu.select_uid(MENUID_VIEW_TYPES, Flags&cCTYPE);
20857 view_menu.select_uid(MENUID_VIEW_INFO, ShowInfo);
20858 view_menu.select_uid(MENUID_VIEW_SQUARES, ShowSquares);
20859 view_menu.select_uid(MENUID_VIEW_FFCS, ShowFFCs);
20860 view_menu.select_uid(MENUID_VIEW_SCRIPTNAMES, ShowFFScripts);
20861 view_menu.select_uid(MENUID_VIEW_GRID, ShowGrid);
20862 view_menu.select_uid(MENUID_VIEW_SCREENGRID, ShowScreenGrid);
20863 view_menu.select_uid(MENUID_VIEW_REGIONGRID, ShowRegionGrid);
20864 view_menu.select_uid(MENUID_VIEW_CURSCROUTLINE, ShowCurScreenOutline);
20865 view_menu.select_uid(MENUID_VIEW_DARKNESS, get_qr(qr_NEW_DARKROOM) && (Flags&cNEWDARK));
20866 view_menu.select_uid(MENUID_VIEW_L2BG, ViewLayer2BG);
20867 view_menu.select_uid(MENUID_VIEW_L3BG, ViewLayer3BG);
20868 view_menu.select_uid(MENUID_VIEW_LAYERHIGHLIGHT, ActiveLayerHighlight);
20869 view_menu.select_uid(MENUID_VIEW_HIGH_QUALITY_SCREEN_RENDERING, HighQualityScreenRendering);
20870
20871 maps_menu.disable_uid(MENUID_MAPS_NEXT, !map_count || Map.getCurrMap() >= map_count);
20872 maps_menu.disable_uid(MENUID_MAPS_PREV, Map.getCurrMap()<=0);
20873
20874 etc_menu.disable_uid(MENUID_ETC_VIDMODE, isFullScreen()==1);
20875 etc_menu.select_uid(MENUID_ETC_FULLSCREEN, isFullScreen()==1);
20876
20877 if(!update_dialog(player2))
20878 exiting_program = true;
20879
20880 //clear_keybuf();
20881 handle_close_btn_quit();
20882 }
20883
20884 zq_exit(0);
20885 return 0;
20886 }
20887 END_OF_MAIN()
20888
20889 11 void zq_exit(int code)
20890 {
20891 11 set_is_exiting();
20892 11 parser_console.kill();
20893 11 killConsole();
20894
20895 11 quit_game();
20896 11 allegro_exit();
20897 11 exit(code);
20898 }
20899
20900 4 void init_bitmap(BITMAP** bmp, int32_t w, int32_t h)
20901 {
20902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(*bmp)
20903 destroy_bitmap(*bmp);
20904 4 *bmp = create_bitmap_ex(8,w,h);
20905 4 clear_bitmap(*bmp);
20906 4 }
20907 1 void load_size_poses()
20908 {
20909 1 ttip_uninstall_all();
20910
20911 1 FONT* favcmdfont = get_custom_font(CFONT_FAVCMD);
20912 1 FONT* guifont = get_custom_font(CFONT_GUI);
20913
20914 1 d_nbmenu_proc(MSG_START, &dialogs[0], 0);
20915
20916 1 commands_list.xscale = command_buttonwidth;
20917 1 commands_list.yscale = 10+text_height(favcmdfont);
20918
20919 1 auto drawmode_wid = 64;
20920
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 for(auto q = 0; q < dm_max; ++q)
20921 {
20922 6 auto wid = text_length(guifont, dm_names[q]);
20923
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(wid > drawmode_wid)
20924 drawmode_wid = wid;
20925 6 }
20926
20927 //Main GUI objects
20928
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(is_compact)
20929 {
20930 1 num_combo_cols = 2;
20931 1 combo_col_scale = 16;
20932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(compact_merged_combopane)
20933 {
20934 1 num_combo_cols = 1;
20935 1 combo_col_scale = 32;
20936 1 }
20937
20938 1 mapscreen_x=0;
20939 1 mapscreen_y=dialogs[0].h;
20940 1 mapscreen_screenunit_scale=3;
20941 1 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
20942 1 showedges=0;
20943 1 showallpanels=0;
20944
20945 1 blackout_color=8;
20946
20947 1 auto mapscr_wid = (((showedges?2:0)+16)*16*mapscreen_screenunit_scale);
20948 1 combolist_window.w=zq_screen_w-mapscr_wid;
20949 1 combolist_window.x=zq_screen_w-combolist_window.w;
20950
20951 1 favorites_window.x=combolist_window.x;
20952 1 favorites_window.w=combolist_window.w;
20953 1 favorites_window.h=136;
20954 1 favorites_window.y=zq_screen_h-favorites_window.h;
20955
20956 1 combolist_window.y=0;
20957 1 combolist_window.h=favorites_window.y-combolist_window.y;
20958
20959 1 combo_preview.x=zq_screen_w-32-8;
20960 1 combo_preview.y=combolist_window.y+6;
20961 1 combo_preview.w=32;
20962 1 combo_preview.h=32;
20963 1 combo_preview2.clear();
20964
20965 1 auto col_wid = 4*combo_col_scale;
20966 1 auto cols_wid = col_wid * num_combo_cols;
20967 1 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
20968
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for(auto q = 0; q < num_combo_cols; ++q)
20969 {
20970 1 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
20971 1 combolist[q].y=combolist_window.y+54;
20972 1 combolist[q].w=4;
20973 1 combolist[q].h=compact_merged_combopane ? 15 : 30;
20974 1 combolist[q].xscale = combo_col_scale;
20975 1 combolist[q].yscale = combo_col_scale;
20976
20977 1 comboaliaslist[q].x = combolist[q].x;
20978 1 comboaliaslist[q].y = combolist[q].y;
20979 1 comboaliaslist[q].w = 4;
20980 1 comboaliaslist[q].h = compact_merged_combopane ? 13 : 26;
20981 1 comboaliaslist[q].xscale = combo_col_scale;
20982 1 comboaliaslist[q].yscale = combo_col_scale;
20983
20984 1 combolistscrollers[q].w=2;
20985 1 combolistscrollers[q].h=1;
20986 1 combolistscrollers[q].xscale=11;
20987 1 combolistscrollers[q].yscale=11;
20988 1 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
20989 1 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-3;
20990 1 }
20991
20992 1 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
20993 1 comboalias_preview.h=64;
20994 1 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
20995 1 comboalias_preview.w=64;
20996
20997 1 combo_merge_btn.w = 20;
20998 1 combo_merge_btn.h = 20;
20999 1 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
21000 1 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
21001
21002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(num_combo_cols == 1)
21003 {
21004 1 combolistscrollers[0].x += 34;
21005 1 }
21006 1 drawmode_btn.x = combolist_window.x-drawmode_wid;
21007 1 drawmode_btn.y = 0;
21008 1 drawmode_btn.w = drawmode_wid;
21009 1 drawmode_btn.h = mapscreen_y;
21010
21011 1 compactbtn.w = text_length(guifont,"> Compact")+10;
21012 1 compactbtn.x = drawmode_btn.x-compactbtn.w;
21013 1 compactbtn.y = drawmode_btn.y;
21014 1 compactbtn.h = drawmode_btn.h;
21015
21016 1 zoominbtn.w = text_length(guifont,"+")+10;
21017 1 zoominbtn.x = compactbtn.x-zoominbtn.w;
21018 1 zoominbtn.y = compactbtn.y;
21019 1 zoominbtn.h = compactbtn.h;
21020
21021 1 zoomoutbtn.w = text_length(guifont,"-")+10;
21022 1 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
21023 1 zoomoutbtn.y = compactbtn.y;
21024 1 zoomoutbtn.h = compactbtn.h;
21025
21026
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
10 for(int32_t i=0; i<=8; i++)
21027 {
21028 9 map_page_bar[i].w = 48;
21029 9 map_page_bar[i].x = mapscreen_x+(i*48);
21030 9 map_page_bar[i].y = mapscreen_y+(11*16*mapscreen_screenunit_scale);
21031 9 map_page_bar[i].h = text_height(guifont)+12;
21032 9 }
21033
21034 1 minimap.w=7+48*3;
21035 1 minimap.h=16+27*3;
21036
21037 1 layer_panel.x=map_page_bar[6].x;
21038 1 layer_panel.y=map_page_bar[0].y;
21039 1 layer_panel.w=combolist_window.x - layer_panel.x;
21040 1 layer_panel.h=map_page_bar[0].h;
21041 1 layerpanel_buttonwidth = 51;
21042 1 layerpanel_buttonheight = layer_panel.h;
21043 1 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
21044 1 layerpanel_checkbox_wid = 15;
21045
21046 1 minimap.x=3;
21047 1 minimap.y=layer_panel.y+layer_panel.h+4;
21048
21049 1 real_minimap.x = minimap.x+3;
21050 1 real_minimap.y = minimap.y+5;
21051 1 real_minimap.w = 16;
21052 1 real_minimap.h = 9;
21053 1 real_minimap.xscale = 9;
21054 1 real_minimap.yscale = 9;
21055 1 real_minimap.fw = real_minimap.xscale*8;
21056 1 real_minimap.fh = real_minimap.yscale*8;
21057
21058 1 int upscale_mm = 3;
21059 1 int xwid = real_minimap.tw()*(upscale_mm-1);
21060 1 int xhei = real_minimap.th()*(upscale_mm-1);
21061 1 minimap_zoomed.set(minimap.x, minimap.y-xhei, minimap.w+xwid, minimap.h+xhei+4);
21062 1 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
21063 1 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
21064 1 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
21065
21066 1 screrrorpos.x = combolist_window.x - 3;
21067 1 screrrorpos.y = layer_panel.y - 16;
21068
21069 1 mouse_scroll_h=10;
21070
21071 1 favorites_list.x=favorites_window.x+8;
21072 1 favorites_list.y=favorites_window.y+16;
21073 1 favorites_list.xscale = 16;
21074 1 favorites_list.yscale = 16;
21075 1 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
21076 1 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
21077
21078 1 commands_list.w=4;
21079
21080 1 int bh = commands_list.yscale;
21081 1 int bw = 26;
21082 1 commands_window.w=commands_list.w*commands_list.xscale+10+bw;
21083 1 commands_window.x=combolist_window.x-commands_window.w;
21084 1 commands_window.y=layer_panel.y+layer_panel.h;
21085 1 commands_window.h=zq_screen_h-commands_window.y;
21086 1 int bx = commands_window.x+2;
21087
21088 1 commands_list.y=commands_window.y+4;
21089 1 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
21090 1 commands_list.x=bx+bw;
21091
21092 1 commands_zoombtn.w = bw;
21093 1 commands_zoombtn.h = bh;
21094 1 commands_zoombtn.x = bx;
21095 1 commands_zoombtn.y = commands_list.y;
21096
21097 1 commands_infobtn.w = bw;
21098 1 commands_infobtn.h = bh;
21099 1 commands_infobtn.x = bx;
21100 1 commands_infobtn.y = commands_zoombtn.y + commands_infobtn.h;
21101
21102 1 commands_x.w = bw;
21103 1 commands_x.h = bh;
21104 1 commands_x.x = bx;
21105 1 commands_x.y = commands_infobtn.y + commands_x.h;
21106
21107 1 commands_txt.clear();
21108
21109 1 main_panel.x = 0;
21110 1 main_panel.y = layer_panel.y+layer_panel.h;
21111 1 main_panel.w = commands_window.x - main_panel.x;
21112 1 main_panel.h = 76+32;
21113 1 preview_panel = main_panel;
21114 1 preview_panel.x = 0;
21115 1 preview_panel.w = commands_window.x - preview_panel.x;
21116
21117 1 preview_text.x = preview_panel.x+3;
21118 1 preview_text.y = preview_panel.y+3;
21119 1 preview_text.w = 2;
21120 1 preview_text.h = 6;
21121 1 preview_text.xscale = 10;
21122 1 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
21123
21124 1 panel_align = 1;
21125 1 int swapbtnw = 32, swapbtnh = 20;
21126 1 int swapbtnx = main_panel.x+main_panel.tw()-swapbtnw;
21127 1 squarepanel_swap_btn.set(swapbtnx, zq_screen_h-swapbtnh, swapbtnw, swapbtnh);
21128
21129 1 int sqx = minimap.x+minimap.tw();
21130 1 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
21131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(compact_square_panels)
21132 {
21133 int cmpy = main_panel.y+(main_panel.th()/2);
21134 squarepanel_up_btn.set(swapbtnx, cmpy-swapbtnh, swapbtnw, swapbtnh);
21135 squarepanel_down_btn.set(swapbtnx, cmpy, swapbtnw, swapbtnh);
21136
21137 txtoffs_single.x = 18;
21138 txtoffs_single.y = 36;
21139 txtoffs_double_1.x = 18;
21140 txtoffs_double_1.y = 36;
21141 txtoffs_double_2.x = 18;
21142 txtoffs_double_2.y = 36 + text_height(get_custom_font(CFONT_GUI));
21143
21144 //Clear them all- if they stay cleared, they are invisible.
21145 itemsqr_pos.clear();
21146 stairsqr_pos.clear();
21147 warparrival_pos.clear();
21148 flagsqr_pos.clear();
21149 enemy_prev_pos.clear();
21150 for(int q = 0; q < 4; ++q)
21151 warpret_pos[q].clear();
21152
21153 int sqr_x1 = sqx+12;
21154 int sqr_y1 = main_panel.y+12;
21155 int sqr_xoffs = (16*2)+4 + 12;
21156 switch(compact_active_panel)
21157 {
21158 case 0: //Warp Squares
21159 {
21160 int x = sqr_x1;
21161 for(int q = 0; q < 4; ++q)
21162 {
21163 warpret_pos[q].set(x,sqr_y1,(16*2)+4,(16*2)+4);
21164 x += sqr_xoffs;
21165 }
21166 break;
21167 }
21168 case 1: //Other Squares
21169 {
21170 itemsqr_pos.set(sqr_x1+(sqr_xoffs*0), sqr_y1, (16*2)+4,(16*2)+4);
21171 stairsqr_pos.set(sqr_x1+(sqr_xoffs*1), sqr_y1, (16*2)+4,(16*2)+4);
21172 warparrival_pos.set(sqr_x1+(sqr_xoffs*2), sqr_y1, (16*2)+4,(16*2)+4);
21173 flagsqr_pos.set(sqr_x1+(sqr_xoffs*3), sqr_y1, (16*2)+4,(16*2)+4);
21174 break;
21175 }
21176 case 2: //Enemy Preview
21177 {
21178 enemy_prev_pos.set(sqr_x1, sqr_y1, 5, 2, 32, 32);
21179 break;
21180 }
21181 }
21182 }
21183 else
21184 {
21185 1 squarepanel_up_btn.clear();
21186 1 squarepanel_down_btn.clear();
21187 1 txtoffs_single.x = 10;
21188 1 txtoffs_single.y = 22;
21189 1 txtoffs_double_1.x = 10;
21190 1 txtoffs_double_1.y = 22;
21191 1 txtoffs_double_2.x = 10;
21192 1 txtoffs_double_2.y = 30;
21193
21194
21195 1 int sqr_x1 = sqx+24;
21196 1 int sqr_y1 = main_panel.y+12;
21197 1 int sqr_y2 = sqr_y1+42;
21198 1 int sqr_xdist = 32;
21199 1 itemsqr_pos.set(sqr_x1+(sqr_xdist*0),sqr_y1,20,20);
21200 1 stairsqr_pos.set(sqr_x1+(sqr_xdist*1),sqr_y1,20,20);
21201 1 warparrival_pos.set(sqr_x1+(sqr_xdist*2),sqr_y1,20,20);
21202 1 flagsqr_pos.set(sqr_x1+(sqr_xdist*3),sqr_y1,20,20);
21203
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for(auto q = 0; q < 4; ++q)
21204 {
21205 4 warpret_pos[q].set(sqr_x1+(sqr_xdist*q),sqr_y2,20,20);
21206 4 }
21207 1 enemy_prev_pos.set(sqr_x1+(sqr_xdist*4), sqr_y1, 4, 3, 16, 16);
21208 1 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
21209 1 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
21210 }
21211
21212 1 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
21213 1 combopool_preview.x=comboaliaslist[0].x;
21214 1 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
21215 1 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
21216 1 combopool_preview.h=zq_screen_h-8-combopool_preview.y;
21217 1 combopool_preview.w -= combopool_preview.w%16;
21218 1 combopool_preview.h -= combopool_preview.h%16;
21219
21220 1 FONT* tfont = get_zc_font(font_lfont_l);
21221 1 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
21222 1 combopool_prevbtn.h = 11;
21223 1 combopool_prevbtn.x = combopool_preview.x;
21224 1 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
21225
21226 1 mappage_count = 6;
21227
21228 1 txfont = get_zc_font(font_lfont_l);
21229 1 combo_preview_text1.set(combo_preview.x-5,combo_preview.y,1,3,1,text_height(txfont));
21230 1 combo_preview_text2.clear();
21231
21232 1 favorites_x.w = 17;
21233 1 favorites_infobtn.w = 17;
21234 1 favorites_zoombtn.w = 17;
21235 1 favorites_pgleft.w = 17;
21236 1 favorites_pgright.w = 17;
21237 1 }
21238 else
21239 {
21240 num_combo_cols = 4;
21241 combo_col_scale = 16;
21242 if(large_merged_combopane)
21243 {
21244 num_combo_cols = 2;
21245 combo_col_scale = 32;
21246 }
21247
21248 mapscreen_x=0;
21249 mapscreen_y=dialogs[0].h;
21250 mapscreen_screenunit_scale=2;
21251 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
21252 if (HighQualityScreenRendering)
21253 showedges=Map.getViewSize() == 1 ? 1 : 0;
21254 else
21255 showedges=Map.getViewSize() <= 2 ? 1 : 0;
21256 showallpanels=0;
21257
21258 blackout_color=8;
21259
21260 favorites_window.h=136;
21261 favorites_window.y=zq_screen_h-favorites_window.h;
21262
21263 auto mapscr_wid = (((2)+16)*16*mapscreen_screenunit_scale);
21264 combolist_window.w=zq_screen_w-mapscr_wid;
21265 combolist_window.x=zq_screen_w-combolist_window.w;
21266 combolist_window.y=0;
21267 combolist_window.h=favorites_window.y-combolist_window.y;
21268
21269 favorites_window.x=combolist_window.x;
21270 favorites_window.w=combolist_window.w;
21271
21272 combo_preview.x=(zq_screen_w-(combolist_window.w/2))-40;
21273 combo_preview.y=combolist_window.y+6;
21274 combo_preview.w=32;
21275 combo_preview.h=32;
21276 combo_preview2 = combo_preview;
21277 combo_preview2.x += 48;
21278
21279 auto col_wid = 4*combo_col_scale;
21280 auto cols_wid = col_wid * num_combo_cols;
21281 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
21282 for(auto q = 0; q < num_combo_cols; ++q)
21283 {
21284 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
21285 combolist[q].y=combolist_window.y+60;
21286 combolist[q].w=4;
21287 combolist[q].h=large_merged_combopane ? 15 : 30;
21288 combolist[q].xscale = combo_col_scale;
21289 combolist[q].yscale = combo_col_scale;
21290
21291 comboaliaslist[q].x=combolist[q].x;
21292 comboaliaslist[q].y=combolist[q].y;
21293 comboaliaslist[q].w=4;
21294 comboaliaslist[q].h=large_merged_combopane ? 12 : 25;
21295 comboaliaslist[q].xscale = combo_col_scale;
21296 comboaliaslist[q].yscale = combo_col_scale;
21297
21298 combolistscrollers[q].w=2;
21299 combolistscrollers[q].h=1;
21300 combolistscrollers[q].xscale=11;
21301 combolistscrollers[q].yscale=11;
21302 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
21303 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-2;
21304 }
21305
21306 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
21307 comboalias_preview.h=64;
21308 comboalias_preview.w=64;
21309 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
21310
21311 combo_merge_btn.w = 20;
21312 combo_merge_btn.h = 20;
21313 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
21314 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
21315 squarepanel_swap_btn.clear();
21316 squarepanel_up_btn.clear();
21317 squarepanel_down_btn.clear();
21318
21319 drawmode_btn.x = combolist_window.x-drawmode_wid;
21320 drawmode_btn.y = 0;
21321 drawmode_btn.w = drawmode_wid;
21322 drawmode_btn.h = mapscreen_y;
21323
21324 compactbtn.w = text_length(guifont,"> Compact")+10;
21325 compactbtn.x = drawmode_btn.x-compactbtn.w;
21326 compactbtn.y = drawmode_btn.y;
21327 compactbtn.h = drawmode_btn.h;
21328
21329 zoominbtn.w = text_length(guifont,"+")+10;
21330 zoominbtn.x = compactbtn.x-zoominbtn.w;
21331 zoominbtn.y = compactbtn.y;
21332 zoominbtn.h = compactbtn.h;
21333
21334 zoomoutbtn.w = text_length(guifont,"-")+10;
21335 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
21336 zoomoutbtn.y = compactbtn.y;
21337 zoomoutbtn.h = compactbtn.h;
21338
21339 for(int32_t i=0; i<=8; i++)
21340 {
21341 map_page_bar[i].x = mapscreen_x+(i*16*2*mapscreen_screenunit_scale);
21342 map_page_bar[i].y = mapscreen_y+((13)*16*mapscreen_screenunit_scale);
21343 map_page_bar[i].w = 64;
21344 map_page_bar[i].h = text_height(guifont)+12;
21345 }
21346
21347 minimap.w=7+48*3;
21348 minimap.h=16+27*3;
21349
21350 layer_panel.x=map_page_bar[0].x;
21351 layer_panel.y=map_page_bar[0].y+map_page_bar[0].h;
21352 layer_panel.w=map_page_bar[8].x+map_page_bar[8].w;
21353 layer_panel.h=text_height(guifont)+8;
21354 layerpanel_buttonwidth = 58;
21355 layerpanel_buttonheight = layer_panel.h;
21356 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
21357 layerpanel_checkbox_wid = 14;
21358
21359 commands_list.w=4;
21360 commands_window.w=commands_list.w*commands_list.xscale+16;
21361 commands_window.x=combolist_window.x-commands_window.w;
21362 commands_window.y=layer_panel.y+layer_panel.h;
21363 commands_window.h=zq_screen_h-commands_window.y;
21364
21365 //buttons panel
21366 main_panel.x = 0;
21367 main_panel.y = layer_panel.y+layer_panel.h;
21368 main_panel.w = commands_window.x - main_panel.x;
21369 main_panel.h = zq_screen_h - main_panel.y;
21370 preview_panel = main_panel;
21371
21372 preview_text.x = preview_panel.x+3;
21373 preview_text.y = preview_panel.y+3;
21374 preview_text.w = 1;
21375 preview_text.h = 12;
21376 preview_text.xscale = 10;
21377 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
21378
21379 minimap.x=3;
21380 minimap.y=main_panel.y+4;
21381
21382 real_minimap.x = minimap.x+3;
21383 real_minimap.y = minimap.y+5;
21384 real_minimap.w = 16;
21385 real_minimap.h = 9;
21386 real_minimap.xscale = 9;
21387 real_minimap.yscale = 9;
21388 real_minimap.fw = real_minimap.xscale*8;
21389 real_minimap.fh = real_minimap.yscale*8;
21390
21391 int upscale_mm = 4;
21392 int xwid = real_minimap.tw()*(upscale_mm-1);
21393 int xhei = real_minimap.th()*(upscale_mm-1);
21394 int zh = minimap.h+xhei+4;
21395 minimap_zoomed.set(minimap.x, zq_screen_h-zh, minimap.w+xwid, zh);
21396 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
21397 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
21398 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
21399
21400 screrrorpos.x = 575;
21401 screrrorpos.y = 388;
21402
21403 mouse_scroll_h=10;
21404
21405 favorites_list.x=favorites_window.x+8;
21406 favorites_list.y=favorites_window.y+16;
21407 favorites_list.xscale = 16;
21408 favorites_list.yscale = 16;
21409 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
21410 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
21411
21412 int bh = 16;
21413 int by = commands_window.y+4;
21414 commands_list.y=by+bh;
21415 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
21416 commands_list.x=commands_window.x+8;
21417
21418 commands_x.w = 20;
21419 commands_x.h = bh;
21420 commands_x.x = commands_list.x + commands_list.tw() - commands_x.w;
21421 commands_x.y = by;
21422
21423 commands_infobtn.w = 20;
21424 commands_infobtn.h = bh;
21425 commands_infobtn.x = commands_x.x - commands_infobtn.w;
21426 commands_infobtn.y = by;
21427
21428 commands_zoombtn.w = 20;
21429 commands_zoombtn.h = bh;
21430 commands_zoombtn.x = commands_infobtn.x - commands_zoombtn.w;
21431 commands_zoombtn.y = by;
21432
21433 commands_txt.x = commands_list.x;
21434 commands_txt.y = by+(bh-text_height(get_zc_font(font_lfont_l)))/2;
21435
21436 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
21437 favorites_x.y = favorites_list.y-15;
21438
21439 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
21440 favorites_infobtn.y = favorites_x.y;
21441
21442 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
21443 favorites_zoombtn.y = favorites_infobtn.y;
21444
21445 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
21446 favorites_pgright.y = favorites_zoombtn.y;
21447
21448 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
21449 favorites_pgleft.y = favorites_pgleft.y;
21450
21451 txtoffs_single.x = 22;
21452 txtoffs_single.y = 6;
21453 txtoffs_double_1.x = 22;
21454 txtoffs_double_1.y = 2;
21455 txtoffs_double_2.x = 22;
21456 txtoffs_double_2.y = 10;
21457 panel_align = 0;
21458
21459 int sqx = minimap.x+minimap.tw();
21460 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
21461 int x2 = sqx+4;
21462 int x1 = x2 - (20+(8*3)+2);
21463 int y1 = main_panel.y+10;
21464 int sw = 20, sh = 20;
21465 int offs = sh+4;
21466
21467 itemsqr_pos.set(x2,y1+(0*offs),sw,sh);
21468 flagsqr_pos.set(x2,y1+(1*offs),sw,sh);
21469 stairsqr_pos.set(x2,y1+(2*offs),sw,sh);
21470 warparrival_pos.set(x2,y1+(6*offs),sw,sh);
21471
21472 enemy_prev_pos.x = main_panel.x+14;
21473 enemy_prev_pos.y = main_panel.y+12 + minimap.h;
21474 enemy_prev_pos.w = 4;
21475 enemy_prev_pos.h = 3;
21476 enemy_prev_pos.xscale = 16;
21477 enemy_prev_pos.yscale = 16;
21478 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
21479 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
21480
21481 warpret_pos[0].set(x1,y1+(4*offs),sw,sh);
21482 warpret_pos[1].set(x1,y1+(5*offs),sw,sh);
21483 warpret_pos[2].set(x2,y1+(4*offs),sw,sh);
21484 warpret_pos[3].set(x2,y1+(5*offs),sw,sh);
21485
21486 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
21487 combopool_preview.x=comboaliaslist[0].x;
21488 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
21489 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
21490 combopool_preview.h=(favorites_window.y-combopool_preview.y);//+favorites_window.h-10;
21491 combopool_preview.w -= combopool_preview.w%16;
21492 combopool_preview.h -= combopool_preview.h%16;
21493
21494 FONT* tfont = get_zc_font(font_lfont_l);
21495 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
21496 combopool_prevbtn.h = 11;
21497 combopool_prevbtn.x = combopool_preview.x;
21498 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
21499
21500 mappage_count = 9;
21501
21502 txfont = get_zc_font(font_lfont_l);
21503 combo_preview_text1.set(combo_preview.x-9,combo_preview.y,1,3,1,text_height(txfont));
21504 combo_preview_text2.set(combo_preview2.x+combo_preview2.w+8,combo_preview2.y,1,3,1,text_height(txfont));
21505
21506 favorites_x.w = 30;
21507 favorites_infobtn.w = 30;
21508 favorites_zoombtn.w = 30;
21509 favorites_pgleft.w = 30;
21510 favorites_pgright.w = 30;
21511 }
21512 //Same in all modes
21513 {
21514
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if(is_compact ? compact_zoomed_cmd : large_zoomed_cmd)
21515 {
21516 1 commands_list.w /= 2;
21517 1 commands_list.xscale *= 2;
21518 1 }
21519
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if(is_compact ? compact_zoomed_fav : large_zoomed_fav)
21520 {
21521
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(favorites_list.w%2)
21522 favorites_list.x += (favorites_list.xscale / 2);
21523 1 favorites_list.xscale *= 2;
21524 1 favorites_list.yscale *= 2;
21525 1 favorites_list.w /= 2;
21526 1 favorites_list.h /= 2;
21527 1 }
21528
21529 1 favorites_x.h = 14;
21530 1 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
21531 1 favorites_x.y = favorites_list.y-15;
21532
21533 1 favorites_infobtn.h = favorites_x.h;
21534 1 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
21535 1 favorites_infobtn.y = favorites_x.y;
21536
21537 1 favorites_zoombtn.h = favorites_infobtn.h;
21538 1 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
21539 1 favorites_zoombtn.y = favorites_infobtn.y;
21540
21541 1 favorites_pgright.h = favorites_zoombtn.h;
21542 1 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
21543 1 favorites_pgright.y = favorites_zoombtn.y;
21544
21545 1 favorites_pgleft.h = favorites_pgright.h;
21546 1 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
21547 1 favorites_pgleft.y = favorites_pgright.y;
21548
21549 1 mainbar.x = dialogs[0].x+dialogs[0].w;
21550 1 mainbar.y = 0;
21551 1 mainbar.w = zoomoutbtn.x-mainbar.x;
21552 1 mainbar.h = drawmode_btn.h;
21553 }
21554
21555 //Ensure current combo list selected is valid
21556 1 current_combolist=vbound(current_combolist,0,num_combo_cols-1);
21557 1 current_comboalist=vbound(current_comboalist,0,num_combo_cols-1);
21558 1 current_cpoollist=vbound(current_cpoollist,0,num_combo_cols-1);
21559 1 current_cautolist = vbound(current_cautolist, 0, num_combo_cols - 1);
21560
21561 //Generate bitmaps
21562 1 init_bitmap(&mapscreenbmp,16*(showedges?18:16),16*(showedges?13:11));
21563 1 init_bitmap(&brushbmp,256*mapscreen_screenunit_scale,176*mapscreen_screenunit_scale);
21564 1 init_bitmap(&brushscreen,(256+(showedges?16:0))*mapscreen_screenunit_scale,(176+(showedges?16:0))*mapscreen_screenunit_scale);
21565
21566 1 init_bitmap(&screen2,zq_screen_w,zq_screen_h);
21567
21568 1 center_zq_class_dialogs();
21569 1 center_zq_files_dialogs();
21570 1 center_zq_subscreen_dialogs();
21571 1 center_zq_tiles_dialogs();
21572 1 center_zquest_dialogs();
21573
21574 1 aspect_ratio = zq_screen_h / double(zq_screen_w);
21575
21576 1 mmap_init();
21577 1 }
21578
21579 11 void remove_locked_params_on_exit()
21580 {
21581 11 al_trace("Removing timers. \n");
21582 11 remove_int(fps_callback);
21583 11 remove_int(dclick_check);
21584 11 }
21585
21586 11 void destroy_bitmaps_on_exit()
21587 {
21588 11 al_trace("Cleaning bitmaps...");
21589 11 destroy_bitmap(screen2);
21590 11 destroy_bitmap(mapscreenbmp);
21591 11 destroy_bitmap(dmapbmp_small);
21592 11 destroy_bitmap(dmapbmp_large);
21593 11 destroy_bitmap(brushbmp);
21594 11 destroy_bitmap(brushscreen);
21595 11 al_trace("...");
21596
21597
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 11 times.
539 for(int32_t i=0; i<MOUSE_BMP_MAX*4; i++)
21598 {
21599 528 destroy_bitmap(mouse_bmp[i/4][i%4]);
21600 528 destroy_bitmap(mouse_bmp_1x[i/4][i%4]);
21601 528 }
21602
21603
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 11 times.
363 for(int32_t i=0; i<ICON_BMP_MAX*4; i++)
21604 352 destroy_bitmap(icon_bmp[i/4][i%4]);
21605
21606
2/2
✓ Branch 0 taken 704 times.
✓ Branch 1 taken 11 times.
715 for(int32_t i=0; i<16*4; i++)
21607 704 destroy_bitmap(flag_bmp[i/4][i%4]);
21608
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 11 times.
33 for(int32_t i=0; i<2; i++)
21609 22 destroy_bitmap(select_bmp[i]);
21610
21611
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 11 times.
99 for(int32_t i=0; i<MAXARROWS; i++)
21612 88 destroy_bitmap(arrow_bmp[i]);
21613
21614 11 al_trace(" OK. \n");
21615 11 }
21616
21617
21618 11 void quit_game()
21619 {
21620 11 set_last_timed_save(nullptr);
21621 11 save_config_file();
21622 11 zc_set_palette(black_palette);
21623 11 zc_stop_midi();
21624
21625 11 remove_locked_params_on_exit();
21626
21627 11 al_trace("Cleaning sfx. \n");
21628
21629
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<WAV_COUNT; i++)
21630 {
21631
2/2
✓ Branch 0 taken 2805 times.
✓ Branch 1 taken 11 times.
2816 if(customsfxdata[i].data!=NULL)
21632 {
21633 // delete [] customsfxdata[i].data;
21634 2805 free(customsfxdata[i].data);
21635 2805 }
21636
21637
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] sfx_string[i];
21638 2816 }
21639
21640
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXWPNS; i++)
21641 {
21642
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] weapon_string[i];
21643 2816 }
21644
21645
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXITEMS; i++)
21646 {
21647
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] item_string[i];
21648 2816 }
21649
21650
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<eMAXGUYS; i++)
21651 {
21652
1/2
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
5632 delete [] guy_string[i];
21653 5632 }
21654
21655 11 al_trace("Cleaning script buffer. \n");
21656
21657
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
21658 {
21659
2/4
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5632 times.
5632 if(ffscripts[i]!=NULL) delete ffscripts[i];
21660 5632 }
21661
21662
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
21663 {
21664
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(itemscripts[i]!=NULL) delete itemscripts[i];
21665 2816 }
21666
21667
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
21668 {
21669
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(guyscripts[i]!=NULL) delete guyscripts[i];
21670 2816 }
21671
21672
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
21673 {
21674
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
21675 2816 }
21676
21677
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
21678 {
21679
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
21680 2816 }
21681
21682
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
21683 {
21684
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(screenscripts[i]!=NULL) delete screenscripts[i];
21685 2816 }
21686
21687
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 11 times.
44 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
21688 {
21689
2/4
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 33 times.
33 if(globalscripts[i]!=NULL) delete globalscripts[i];
21690 33 }
21691
21692
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 11 times.
66 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
21693 {
21694
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 55 times.
55 if(playerscripts[i]!=NULL) delete playerscripts[i];
21695 55 }
21696
21697
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
21698 {
21699
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
21700 2816 }
21701
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
21702 {
21703
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
21704 2816 }
21705
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
21706 {
21707
2/4
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5632 times.
5632 if(comboscripts[i]!=NULL) delete comboscripts[i];
21708 5632 }
21709
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2816 times.
2827 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
21710 {
21711
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
21712 2816 }
21713
21714 11 al_trace("Cleaning qst buffers. \n");
21715 11 del_qst_buffers();
21716
21717
21718 11 al_trace("Cleaning midis. \n");
21719
21720
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(customtunes)
21721 {
21722
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
21723 2816 customtunes[i].reset();
21724
21725 11 free(customtunes);
21726 11 }
21727
21728 11 al_trace("Cleaning undotilebuf. \n");
21729
21730 11 undocombobuf.clear();
21731
21732
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(newundotilebuf)
21733 {
21734
2/2
✓ Branch 0 taken 2359500 times.
✓ Branch 1 taken 11 times.
2359511 for(int32_t i=0; i<NEWMAXTILES; i++)
21735
1/2
✓ Branch 0 taken 2359500 times.
✗ Branch 1 not taken.
2359500 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
21736
21737 11 free(newundotilebuf);
21738 11 }
21739
21740
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(filepath) free(filepath);
21741
21742
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(datapath) free(datapath);
21743
21744
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(midipath) free(midipath);
21745
21746
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(imagepath) free(imagepath);
21747
21748
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(tmusicpath) free(tmusicpath);
21749
21750
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(last_timed_save) free(last_timed_save);
21751
21752 11 destroy_bitmaps_on_exit();
21753 11 }
21754
21755 void quit_game2()
21756 {
21757 set_last_timed_save(nullptr);
21758 save_config_file();
21759 zc_set_palette(black_palette);
21760 zc_stop_midi();
21761
21762 remove_locked_params_on_exit();
21763
21764 al_trace("Cleaning sfx. \n");
21765
21766 for(int32_t i=0; i<WAV_COUNT; i++)
21767 {
21768 if(customsfxdata[i].data!=NULL)
21769 {
21770 // delete [] customsfxdata[i].data;
21771 free(customsfxdata[i].data);
21772 }
21773
21774 delete [] sfx_string[i];
21775 }
21776
21777 for(int32_t i=0; i<MAXWPNS; i++)
21778 {
21779 delete [] weapon_string[i];
21780 }
21781
21782 for(int32_t i=0; i<MAXITEMS; i++)
21783 {
21784 delete [] item_string[i];
21785 }
21786
21787 for(int32_t i=0; i<eMAXGUYS; i++)
21788 {
21789 delete [] guy_string[i];
21790 }
21791
21792 al_trace("Cleaning script buffer. \n");
21793
21794 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
21795 {
21796 if(ffscripts[i]!=NULL) delete ffscripts[i];
21797 }
21798
21799 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
21800 {
21801 if(itemscripts[i]!=NULL) delete itemscripts[i];
21802 }
21803
21804 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
21805 {
21806 if(guyscripts[i]!=NULL) delete guyscripts[i];
21807 }
21808
21809 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
21810 {
21811 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
21812 }
21813
21814 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
21815 {
21816 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
21817 }
21818
21819 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
21820 {
21821 if(screenscripts[i]!=NULL) delete screenscripts[i];
21822 }
21823
21824 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
21825 {
21826 if(globalscripts[i]!=NULL) delete globalscripts[i];
21827 }
21828
21829 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
21830 {
21831 if(playerscripts[i]!=NULL) delete playerscripts[i];
21832 }
21833
21834 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
21835 {
21836 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
21837 }
21838 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
21839 {
21840 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
21841 }
21842 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
21843 {
21844 if(comboscripts[i]!=NULL) delete comboscripts[i];
21845 }
21846 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
21847 {
21848 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
21849 }
21850
21851 al_trace("Cleaning qst buffers. \n");
21852 del_qst_buffers();
21853
21854
21855 al_trace("Cleaning midis. \n");
21856
21857 if(customtunes)
21858 {
21859 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
21860 customtunes[i].reset();
21861
21862 free(customtunes);
21863 }
21864
21865 al_trace("Cleaning undotilebuf. \n");
21866
21867 undocombobuf.clear();
21868
21869 if(newundotilebuf)
21870 {
21871 for(int32_t i=0; i<NEWMAXTILES; i++)
21872 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
21873
21874 free(newundotilebuf);
21875 }
21876
21877 if(filepath) free(filepath);
21878
21879 if(datapath) free(datapath);
21880
21881 if(midipath) free(midipath);
21882
21883 if(imagepath) free(imagepath);
21884
21885 if(tmusicpath) free(tmusicpath);
21886
21887 if(last_timed_save) free(last_timed_save);
21888 }
21889
21890 1 void center_zquest_dialogs()
21891 {
21892 1 jwin_center_dialog(assignscript_dlg);
21893 1 center_zq_cset_dialogs();
21894 1 jwin_center_dialog(change_track_dlg);
21895 1 jwin_center_dialog(csetfix_dlg);
21896 1 center_zq_door_dialogs();
21897 1 jwin_center_dialog(editcomboa_dlg);
21898 1 jwin_center_dialog(editinfo_dlg);
21899 1 jwin_center_dialog(editshop_dlg);
21900 1 jwin_center_dialog(list_dlg);
21901 1 jwin_center_dialog(loadmap_dlg);
21902 1 jwin_center_dialog(misccolors_dlg);
21903 1 jwin_center_dialog(newcomboa_dlg);
21904 1 jwin_center_dialog(orgcomboa_dlg);
21905 1 jwin_center_dialog(path_dlg);
21906 1 jwin_center_dialog(screen_pal_dlg);
21907 1 jwin_center_dialog(secret_dlg);
21908 1 jwin_center_dialog(showpal_dlg);
21909 1 jwin_center_dialog(strlist_dlg);
21910 1 jwin_center_dialog(template_dlg);
21911 1 jwin_center_dialog(tp_dlg);
21912 1 jwin_center_dialog(tilewarp_dlg);
21913 1 jwin_center_dialog(sidewarp_dlg);
21914 1 jwin_center_dialog(warpring_dlg);
21915 1 center_zscript_dialogs();
21916 1 }
21917
21918
21919 void animate_coords()
21920 {
21921 coord_frame=(coord_timer>>3)&3;
21922
21923 if(++coord_timer>=(1<<5))
21924 {
21925 coord_timer=0;
21926 }
21927 }
21928
21929 static const char *help_list[] =
21930 {
21931 "PREVIEW MODE",
21932 "PgUp/PgDn - Scroll through hotkey list",
21933 "Esc/Enter - Exit Preview Mode",
21934 "R - Restore screen to original state",
21935 "C - Toggle combo cycling On/Off",
21936 "S - Trigger screen secrets",
21937 "Q/W/F - These still work",
21938 "P - Pause everything",
21939 "A - Advance frame-by-frame",
21940 "1-4 - Trigger tile warp A-D",
21941 "5-8 - Trigger side warp A-D",
21942 "9 - Enable timed warps",
21943 "",
21944 "",
21945 };
21946
21947 void do_previewtext()
21948 {
21949 FONT* oldfont = font;
21950 font = get_zc_font(font_lfont_l);
21951
21952 //Put in help areas
21953 auto& sqr = preview_text;
21954 int ind = 0, len = 0;
21955 for(int q = 0; q < 12; ++q)
21956 {
21957 int l = text_length(font, help_list[q]);
21958 if(len < l) len = l;
21959 }
21960 sqr.xscale = len+2;
21961 sqr.yscale = text_height(font);
21962 for(int col = 0; col < sqr.w; ++col)
21963 {
21964 for(int row = 0; row < sqr.h; ++row)
21965 {
21966 auto& line = sqr.subsquare(col,row);
21967 textprintf_ex(screen,font,line.x,line.y,jwin_pal[jcTEXTFG],-1,"%s",help_list[ind++]);
21968 }
21969 }
21970
21971 font = oldfont;
21972 }
21973
21974
21975 bool reload_fonts = false;
21976 void run_zq_frame()
21977 {
21978 if(reload_fonts)
21979 {
21980 init_custom_fonts();
21981 load_size_poses();
21982 reload_fonts = false;
21983 }
21984
21985 handlePreviewMode();
21986 domouse();
21987 get_screen_rti()->freeze = false;
21988 custom_vsync();
21989 refresh(rCLEAR|rALL);
21990 }
21991 1 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c)
21992 {
21993
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 switch(msg)
21994 {
21995 case MSG_VSYNC:
21996 run_zq_frame();
21997 break;
21998 case MSG_GOTMOUSE:
21999 case MSG_XCHAR:
22000 ComboBrushPause=1;
22001 refresh(rMAP);
22002 ComboBrushPause=0;
22003 clear_tooltip();
22004 break;
22005 }
22006
22007 1 return GuiMenu::proc(msg,d,c);
22008 }
22009
22010 bool prv_press=false;
22011
22012 void dopreview()
22013 {
22014 refresh(rMAP);
22015
22016 while(!(gui_mouse_b()))
22017 {
22018 if(keypressed())
22019 {
22020 if(!prv_press)
22021 {
22022 prv_press=true;
22023
22024 switch(readkey()>>8)
22025 {
22026 case KEY_ESC:
22027 case KEY_ENTER:
22028 case KEY_ENTER_PAD:
22029 goto finished;
22030 break;
22031
22032 case KEY_F:
22033 Flags^=cFLAGS;
22034 refresh(rMAP);
22035 break;
22036
22037 case KEY_R:
22038 onReloadPreview();
22039 break;
22040
22041 case KEY_S:
22042 onSecretsPreview();
22043 break;
22044
22045 case KEY_C:
22046 onCopy();
22047 break;
22048
22049 case KEY_A:
22050 onAKey();
22051 break;
22052
22053 case KEY_P:
22054 onP();
22055 break;
22056
22057 case KEY_L:
22058 onShowDarkness();
22059 break;
22060
22061 case KEY_1:
22062 Map.prv_dowarp(0,0);
22063 prv_warp=0;
22064 break;
22065
22066 case KEY_2:
22067 Map.prv_dowarp(0,1);
22068 prv_warp=0;
22069 break;
22070
22071 case KEY_3:
22072 Map.prv_dowarp(0,2);
22073 prv_warp=0;
22074 break;
22075
22076 case KEY_4:
22077 Map.prv_dowarp(0,3);
22078 prv_warp=0;
22079 break;
22080
22081 case KEY_5:
22082 Map.prv_dowarp(1,0);
22083 prv_warp=0;
22084 break;
22085
22086 case KEY_6:
22087 Map.prv_dowarp(1,1);
22088 prv_warp=0;
22089 break;
22090
22091 case KEY_7:
22092 Map.prv_dowarp(1,2);
22093 prv_warp=0;
22094 break;
22095
22096 case KEY_8:
22097 Map.prv_dowarp(1,3);
22098 prv_warp=0;
22099 break;
22100
22101 case KEY_9:
22102 if(prv_twon)
22103 {
22104 prv_twon=0;
22105 Map.set_prvtime(0);
22106 prv_warp=0;
22107 }
22108 else
22109 {
22110 Map.set_prvtime(Map.get_prvscr()->timedwarptics);
22111 prv_twon=1;
22112 }
22113
22114 break;
22115
22116 case KEY_W:
22117 onShowWalkability();
22118 break;
22119
22120 case KEY_Q:
22121 onShowComboInfoCSet();
22122 break;
22123 }
22124 }
22125 else
22126 {
22127 readkey();
22128 }
22129 }
22130 else
22131 {
22132 prv_press=false;
22133 }
22134
22135 if(prv_warp)
22136 {
22137 Map.prv_dowarp(1,0);
22138 prv_warp=0;
22139 }
22140
22141 if(Map.get_prvfreeze())
22142 {
22143 if(Map.get_prvadvance())
22144 {
22145 custom_vsync();
22146 Map.set_prvadvance(0);
22147 }
22148 }
22149 else
22150 {
22151 custom_vsync();
22152 Map.set_prvadvance(0);
22153 }
22154
22155 refresh(rALL);
22156 }
22157
22158 finished:
22159 //Flags=of;
22160 reset_combo_animations();
22161 reset_combo_animations2();
22162 MouseSprite::set(ZQM_NORMAL);
22163 prv_mode=0;
22164 prv_warp=0;
22165 Map.end_prv();
22166 Map.refresh_color();
22167 refresh(rMAP+rMENU);
22168
22169 while(gui_mouse_b())
22170 {
22171 /* do nothing */
22172 rest(1);
22173 }
22174 }
22175
22176 void call_vidmode_dlg();
22177 int32_t onZQVidMode()
22178 {
22179 call_vidmode_dlg();
22180 return D_O_K;
22181 }
22182
22183 bool screenIsScrolling()
22184 {
22185 return false;
22186 }
22187
22188 void write_includepaths()
22189 {
22190 FILE* f = fopen("includepaths.txt", "w");
22191 if(f)
22192 {
22193 fwrite(FFCore.includePathString,1,strlen(FFCore.includePathString),f);
22194 fclose(f);
22195 }
22196 }
22197
22198 11 int32_t save_config_file()
22199 {
22200
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!application_has_loaded) return 0;
22201
22202 char qtnametitle[20];
22203 char qtpathtitle[20];
22204 char *datapath2=(char *)malloc(2048);
22205 char *midipath2=(char *)malloc(2048);
22206 char *imagepath2=(char *)malloc(2048);
22207 char *tmusicpath2=(char *)malloc(2048);
22208 strcpy(datapath2, datapath);
22209 strcpy(midipath2, midipath);
22210 strcpy(imagepath2, imagepath);
22211 strcpy(tmusicpath2, tmusicpath);
22212 chop_path(datapath2);
22213 chop_path(midipath2);
22214 chop_path(imagepath2);
22215 chop_path(tmusicpath2);
22216 write_includepaths();
22217
22218 zc_set_config("zquest",data_path_name,datapath2);
22219 zc_set_config("zquest",midi_path_name,midipath2);
22220 zc_set_config("zquest",image_path_name,imagepath2);
22221 zc_set_config("zquest",tmusic_path_name,tmusicpath2);
22222
22223 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
22224 {
22225 window_width = al_get_display_width(all_get_display());
22226 window_height = al_get_display_height(all_get_display());
22227 zc_set_config("zquest","window_width",window_width);
22228 zc_set_config("zquest","window_height",window_height);
22229 }
22230 if (all_get_display() && !all_get_fullscreen_flag() && SaveWinPos)
22231 {
22232 int o_window_x, o_window_y;
22233 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
22234 zc_set_config("zquest", "window_x", o_window_x);
22235 zc_set_config("zquest", "window_y", o_window_y);
22236 }
22237
22238 byte b = 0;
22239 for(int32_t x=0; x<7; x++)
22240 {
22241 set_bit(&b,x,LayerMaskInt[x]);
22242 }
22243
22244 zc_set_config("zquest","layer_mask",b);
22245
22246 flush_config_file();
22247 #ifdef __EMSCRIPTEN__
22248 em_sync_fs();
22249 #endif
22250 free(datapath2);
22251 free(midipath2);
22252 free(imagepath2);
22253 free(tmusicpath2);
22254 return 0;
22255 11 }
22256
22257 int32_t d_timer_proc(int32_t msg, DIALOG *d, int32_t c)
22258 {
22259 //these are here to bypass compiler warnings about unused arguments
22260 c=c;
22261 d=d;
22262
22263 switch(msg)
22264 {
22265 case MSG_IDLE:
22266 #ifdef _WIN32
22267 if(zqUseWin32Proc != FALSE)
22268 win32data.Update(Frameskip); //experimental win32 fixes
22269
22270 #endif
22271
22272 // This has been crashing on Windows, and it saves plenty without it
22273 //check_autosave();
22274 break;
22275 }
22276
22277 return D_O_K;
22278 }
22279
22280 void check_autosave()
22281 {
22282 if (!first_save)
22283 return;
22284
22285 if(AutoSaveInterval>0)
22286 {
22287 time(&auto_save_time_current);
22288 auto_save_time_diff = difftime(auto_save_time_current,auto_save_time_start);
22289
22290 if(auto_save_time_diff>AutoSaveInterval*60)
22291 {
22292 if (!autosaved)
22293 {
22294 MouseSprite::set(ZQM_NORMAL);
22295 replace_extension(last_timed_save, filepath, "qt0", 2047);
22296 set_last_timed_save(last_timed_save);
22297
22298 if((header.zelda_version != ZELDA_VERSION || header.build != VERSION_BUILD))
22299 {
22300 displayinfo("Auto Save","This quest was saved in an older version of ZQuest.\nIf you wish to use the autosave feature, you must manually save the files in this version first.");
22301 time(&auto_save_time_start);
22302 return;
22303 }
22304
22305 int32_t ret = save_quest(last_timed_save, true);
22306
22307 if(ret)
22308 {
22309 displayinfo("Error","Timed save did not complete successfully.");
22310 set_last_timed_save(nullptr);
22311 }
22312 else autosaved = true;
22313
22314 save_config_file();
22315 }
22316 time(&auto_save_time_start);
22317 }
22318 }
22319 }
22320
22321 void flushItemCache(bool) {}
22322 void ringcolor(bool forceDefault)
22323 {
22324 forceDefault=forceDefault;
22325 }
22326
22327 bool item_disabled(int32_t)
22328 {
22329 return false;
22330 }
22331
22332 int32_t onCmdExit()
22333 {
22334 // replaces onExit for the -large button command "Exit"
22335 close_button_quit = true;
22336 return 0;
22337 }
22338
22339 int32_t onQuickCompile()
22340 {
22341 if(do_compile_and_slots(1,false))
22342 {
22343 mark_save_dirty();
22344 InfoDialog("Quick Compile","Success!").show();
22345 }
22346 else
22347 {
22348 InfoDialog("Quick Compile","Failure!").show();
22349 }
22350 return 0;
22351 }
22352 int32_t onSmartCompile()
22353 {
22354 if(do_compile_and_slots(2,false))
22355 {
22356 mark_save_dirty();
22357 InfoDialog("Smart Compile","Success!").show();
22358 }
22359 else
22360 {
22361 InfoDialog("Smart Compile","Failure!").show();
22362 }
22363 return 0;
22364 }
22365
22366 int32_t strchrnum(char const* str, char c)
22367 {
22368 for(int32_t i=0; str[i]; ++i)
22369 {
22370 if(str[i]==c)
22371 {
22372 return i;
22373 }
22374 }
22375
22376 return -1;
22377 }
22378
22379 int32_t get_longest_line_length(FONT *f, char* str)
22380 {
22381 int32_t maxlen=0;
22382 char* tmpstr = str;
22383 char temp=0;
22384 int32_t t=0;
22385 int32_t new_t=-1;
22386 while(tmpstr[0])
22387 {
22388 t=strchrnum(tmpstr, '\n');
22389
22390 if(t==-1)
22391 {
22392 t=(int32_t)strlen(tmpstr);
22393 }
22394
22395 if((uint32_t)t!=strlen(tmpstr))
22396 {
22397 new_t=t+1;
22398 }
22399 else
22400 {
22401 new_t=-1;
22402 }
22403
22404 temp = tmpstr[t];
22405 tmpstr[t]=0;
22406 maxlen=zc_max(maxlen,text_length(f, tmpstr));
22407 tmpstr[t]=temp;
22408
22409 if(new_t!=-1)
22410 {
22411 tmpstr+=new_t;
22412 }
22413 else break;
22414 }
22415 return maxlen;
22416 }
22417
22418 int32_t count_lines(char const* str)
22419 {
22420 int32_t count=1;
22421
22422 for(word i=0; i<strlen(str); ++i)
22423 {
22424 if(str[i]=='\n')
22425 {
22426 ++count;
22427 }
22428 }
22429
22430 return count;
22431 }
22432
22433 void textbox_out(BITMAP* dest, FONT* font, int x, int y, int fg, int bg, char const* str, int align, size_and_pos* dims)
22434 {
22435 static size_and_pos nilsz;
22436 size_and_pos& txbox = dims ? *dims : nilsz;
22437
22438 char* kill = (char*)malloc(strlen(str)+1);
22439 char *tmpstr = kill;
22440 strcpy(tmpstr,str);
22441
22442 while(tmpstr[0] == '\n')
22443 ++tmpstr;
22444 int len = strlen(tmpstr);
22445 while(tmpstr[len-1] == '\n')
22446 tmpstr[--len] = 0;
22447
22448 txbox.x=x;
22449 txbox.y=y;
22450 int32_t lines=count_lines(tmpstr);
22451 txbox.w = 1;
22452 txbox.h = lines;
22453 txbox.xscale = get_longest_line_length(font, tmpstr);
22454 txbox.yscale = text_height(font);
22455
22456 int ax = 0; //Aligned x
22457 switch(align)
22458 {
22459 case 0: //left
22460 break;
22461 case 1: //center
22462 txbox.x -= txbox.xscale/2;
22463 ax = txbox.xscale/2;
22464 break;
22465 case 2: //right
22466 txbox.x -= txbox.xscale;
22467 ax = txbox.xscale;
22468 break;
22469 }
22470
22471 int bw = txbox.w*txbox.xscale;
22472 int bh = txbox.h*txbox.yscale;
22473 BITMAP* outbmp = create_bitmap_ex(8, bw, bh);
22474 clear_to_color(outbmp, bg);
22475
22476 char temp = 0;
22477 int32_t t=0;
22478 int32_t new_t=-1;
22479 int32_t line=0;
22480
22481 while(tmpstr[t])
22482 {
22483 t=strchrnum(tmpstr, '\n');
22484
22485 if(t==-1)
22486 t=(int32_t)strlen(tmpstr);
22487
22488 if((uint32_t)t!=strlen(tmpstr))
22489 new_t=t+1;
22490 else
22491 new_t=-1;
22492
22493 temp = tmpstr[t];
22494 tmpstr[t]=0;
22495 gui_textout_ln(outbmp, font, (ucc*)tmpstr, ax, (line*txbox.yscale), fg, -1, align);
22496 tmpstr[t]=temp;
22497 ++line;
22498
22499 if(new_t!=-1)
22500 {
22501 tmpstr+=new_t;
22502 t=0;
22503 }
22504 }
22505
22506 blit(outbmp, dest, 0, 0, txbox.x, txbox.y, bw, bh);
22507 destroy_bitmap(outbmp);
22508 free(kill);
22509 }
22510
22511 void highlight_sqr(BITMAP* dest, int color, int x, int y, int w, int h, int thick)
22512 {
22513 for(int q = 0; q < thick; ++q)
22514 {
22515 safe_rect(dest, x+q, y+q, x+w-1-q, y+h-1-q, color);
22516 }
22517 }
22518 void highlight_sqr(BITMAP* dest, int color, size_and_pos const& rec, int thick)
22519 {
22520 highlight_sqr(dest, color, rec.x, rec.y, rec.tw(), rec.th(), thick);
22521 }
22522 void highlight_frag(BITMAP* dest, int color, int x1, int y1, int w, int h, int fw, int fh, int thick)
22523 {
22524 int xc = x1+fw-1;
22525 int yc = y1+fh-1;
22526 int x2 = x1+w-1;
22527 int y2 = y1+h-1;
22528
22529 hline(dest, x1, y1, x2, color);
22530 vline(dest, x1, y1, y2, color);
22531
22532 hline(dest, x1, y2, xc, color);
22533 vline(dest, x2, y1, yc, color);
22534 hline(dest, xc, yc, x2, color);
22535 vline(dest, xc, yc, y2, color);
22536 }
22537 void highlight_frag(BITMAP* dest, int color, size_and_pos const& rec, int thick)
22538 {
22539 highlight_frag(dest, color, rec.x, rec.y, rec.tw(), rec.th(), rec.fw, rec.fh, thick);
22540 }
22541
22542 void highlight(BITMAP* dest, size_and_pos& hl)
22543 {
22544 if(hl.fw > -1 && hl.fh > -1)
22545 {
22546 highlight_frag(dest, hl.data[1], hl, hl.data[0]);
22547 }
22548 else highlight_sqr(dest, hl.data[1], hl, hl.data[0]);
22549 }
22550
22551 std::pair<int, int> get_box_text_size(char const* tipmsg, double txscale)
22552 {
22553 if(txscale < 1) txscale = 1;
22554 char* kill = (char*)malloc(strlen(tipmsg)+1);
22555 char *tmpstr = kill;
22556 strcpy(tmpstr,tipmsg);
22557
22558 while(tmpstr[0] == '\n')
22559 ++tmpstr;
22560 int len = strlen(tmpstr);
22561 while(tmpstr[len-1] == '\n')
22562 tmpstr[--len] = 0;
22563
22564 int32_t lines = count_lines(tmpstr);
22565 int txlen = get_longest_line_length(font, tmpstr);
22566 int txhei = lines*text_height(font);
22567 int tx_sclen = (txlen * txscale);
22568 int tx_schei = (txhei * txscale);
22569 int w = tx_sclen + 8 + 1;
22570 int h = tx_schei + 8 + 1;
22571 if (w > zq_screen_w)
22572 w = zq_screen_w;
22573 if (h > zq_screen_h)
22574 h = zq_screen_h;
22575 return {w, h};
22576 }
22577
22578 void draw_box(BITMAP* destbmp, size_and_pos* pos, char const* tipmsg, double txscale)
22579 {
22580 if(txscale < 1) txscale = 1;
22581 char* kill = (char*)malloc(strlen(tipmsg)+1);
22582 char *tmpstr = kill;
22583 strcpy(tmpstr,tipmsg);
22584
22585 while(tmpstr[0] == '\n')
22586 ++tmpstr;
22587 int len = strlen(tmpstr);
22588 while(tmpstr[len-1] == '\n')
22589 tmpstr[--len] = 0;
22590
22591 auto& box = *pos;
22592 clear_bitmap(destbmp);
22593
22594 int32_t lines=count_lines(tmpstr);
22595 int txlen = get_longest_line_length(font, tmpstr);
22596 int txhei = lines*text_height(font);
22597 int tx_sclen = (txlen * txscale);
22598 int tx_schei = (txhei * txscale);
22599 box.w = tx_sclen + 8 + 1;
22600 box.h = tx_schei + 8 + 1;
22601 if (box.w > zq_screen_w)
22602 box.w = zq_screen_w;
22603 if (box.h > zq_screen_h)
22604 box.h = zq_screen_h;
22605
22606 if(box.x+box.w>=zq_screen_w)
22607 {
22608 box.x=(zq_screen_w - box.w);
22609 }
22610
22611 if(box.y+box.h>=zq_screen_h)
22612 {
22613 box.y=(zq_screen_h - box.h);
22614 }
22615
22616 rectfill(destbmp, 1, 1, box.w-3, box.h-3, jwin_pal[jcTEXTBG]);
22617 rect(destbmp, 0, 0, box.w-2, box.h-2, jwin_pal[jcTEXTFG]);
22618 vline(destbmp, box.w-1, 0, box.h-1, jwin_pal[jcTEXTFG]);
22619 hline(destbmp, 1, box.h-1, box.w-2, jwin_pal[jcTEXTFG]);
22620 destbmp->line[box.h-1][0]=0;
22621 destbmp->line[0][box.w-1]=0;
22622
22623 char temp = 0;
22624 int32_t t=0;
22625 int32_t new_t=-1;
22626 int32_t line=0;
22627
22628 BITMAP* txbmp = create_bitmap_ex(8,box.w,box.h);
22629 clear_bitmap(txbmp);
22630 while(tmpstr[t])
22631 {
22632 t=strchrnum(tmpstr, '\n');
22633
22634 if(t==-1)
22635 {
22636 t=(int32_t)strlen(tmpstr);
22637 }
22638
22639 if((uint32_t)t!=strlen(tmpstr))
22640 {
22641 new_t=t+1;
22642 }
22643 else
22644 {
22645 new_t=-1;
22646 }
22647
22648 temp = tmpstr[t];
22649 tmpstr[t]=0;
22650 textprintf_ex(txbmp, font, 0, (line*text_height(font)), jwin_pal[jcTEXTFG], -1, "%s", tmpstr);
22651 tmpstr[t]=temp;
22652 ++line;
22653
22654 if(new_t!=-1)
22655 {
22656 tmpstr+=new_t;
22657 t=0;
22658 }
22659 }
22660 masked_stretch_blit(txbmp,destbmp,0,0,txlen,txhei,4,4,tx_sclen,tx_schei);
22661 destroy_bitmap(txbmp);
22662 free(kill);
22663 }
22664
22665 void update_tooltip(int32_t x, int32_t y, size_and_pos const& sqr, char const* tipmsg, double scale)
22666 {
22667 update_tooltip(x,y,sqr.x,sqr.y,sqr.w*sqr.xscale,sqr.h*sqr.yscale,tipmsg,sqr.fw,sqr.fh,scale);
22668 }
22669 void update_tooltip(int32_t x, int32_t y, int32_t tx, int32_t ty, int32_t tw, int32_t th, char const* tipmsg, int fw, int fh, double scale)
22670 {
22671 if(!EnableTooltips)
22672 {
22673 return;
22674 }
22675
22676 ttip_install(ttip_global_id, tipmsg, tx, ty, tw, th, x, y, fw, fh);
22677 }
22678
22679 void ZQ_ClearQuestPath()
22680 {
22681 zc_set_config("zquest","win_last_quest",(char const*)nullptr);
22682 strcpy(filepath,"");
22683 }
22684
22685 //FFCore
22686
22687 void FFScript::init(bool for_continue)
22688 {
22689 for ( int32_t q = 0; q < wexLast; q++ ) warpex[q] = 0;
22690 numscriptdraws = 0;
22691 max_ff_rules = qr_MAX;
22692 temp_no_stepforward = 0;
22693 nostepforward = 0;
22694
22695 coreflags = 0;
22696 skip_ending_credits = 0;
22697 music_update_cond = 0;
22698 music_update_flags = 0;
22699 for ( int32_t q = 0; q < susptLAST; q++ ) { system_suspend[q] = false; }
22700
22701 //for ( int32_t q = 0; q < 512; q++ ) FF_rules[q] = 0;
22702 int32_t usr_midi_volume = usr_digi_volume = usr_sfx_volume = usr_music_volume = usr_panstyle = 0;
22703 FF_hero_action = 0;
22704 enemy_removal_point[spriteremovalY1] = -32767;
22705 enemy_removal_point[spriteremovalY2] = 32767;
22706 enemy_removal_point[spriteremovalX1] = -32767;
22707 enemy_removal_point[spriteremovalX2] = 32767;
22708 enemy_removal_point[spriteremovalZ1] = -32767;
22709 enemy_removal_point[spriteremovalZ2] = 32767;
22710
22711 for ( int32_t q = 0; q < 4; q++ )
22712 {
22713 FF_screenbounds[q] = 0;
22714 FF_screen_dimensions[q] = 0;
22715 FF_subscreen_dimensions[q] = 0;
22716 FF_eweapon_removal_bounds[q] = 0;
22717 FF_lweapon_removal_bounds[q] = 0;
22718 }
22719 for ( int32_t q = 0; q < FFSCRIPTCLASS_CLOCKS; q++ )
22720 {
22721 FF_clocks[q] = 0;
22722 }
22723 for ( int32_t q = 0; q < SCRIPT_DRAWING_RULES; q++ )
22724 {
22725 ScriptDrawingRules[q] = 0;
22726 }
22727 for ( int32_t q = 0; q < NUM_USER_MIDI_OVERRIDES; q++ )
22728 {
22729 FF_UserMidis[q] = 0;
22730 }
22731 subscreen_scroll_speed = 0; //make a define for a default and read quest override! -Z
22732 kb_typing_mode = false;
22733 initIncludePaths();
22734 }
22735
22736 void FFScript::updateIncludePaths()
22737 {
22738 includePaths.clear();
22739 int32_t pos = 0; int32_t pathnumber = 0;
22740 for ( int32_t q = 0; includePathString[pos]; ++q )
22741 {
22742 int32_t dest = 0;
22743 char buf[2048] = {0};
22744 while(includePathString[pos] != ';' && includePathString[pos])
22745 {
22746 buf[dest] = includePathString[pos];
22747 ++pos;
22748 ++dest;
22749 }
22750 ++pos;
22751 string str(buf);
22752 includePaths.push_back(str);
22753 }
22754 }
22755
22756 void FFScript::initIncludePaths()
22757 {
22758 memset(includePathString,0,sizeof(includePathString));
22759 FILE* f = fopen("includepaths.txt", "r");
22760 if(f)
22761 {
22762 int32_t pos = 0;
22763 int32_t c;
22764 do
22765 {
22766 c = fgetc(f);
22767 if(c!=EOF)
22768 includePathString[pos++] = c;
22769 }
22770 while(c!=EOF && pos<MAX_INCLUDE_PATH_CHARS);
22771 if(pos<MAX_INCLUDE_PATH_CHARS)
22772 includePathString[pos] = '\0';
22773 includePathString[MAX_INCLUDE_PATH_CHARS-1] = '\0';
22774 fclose(f);
22775 }
22776 else strcpy(includePathString, "include/;headers/;scripts/;");
22777 al_trace("Full path string is: ");
22778 safe_al_trace(includePathString);
22779 al_trace("\n");
22780 updateIncludePaths();
22781
22782 for ( size_t q = 0; q < includePaths.size(); ++q )
22783 {
22784 al_trace("Include path %zu: ",q);
22785 safe_al_trace(includePaths.at(q).c_str());
22786 al_trace("\n");
22787 }
22788 }
22789
22790 int32_t FFScript::getQRBit(int32_t rule)
22791 {
22792 return ( get_qr(rule) ? 1 : 0 );
22793 }
22794
22795 int32_t FFScript::getTime(int32_t type)
22796 {
22797 //struct tm *tm_struct = localtime(time(NULL));
22798 struct tm * tm_struct;
22799 time_t rawtime;
22800 time (&rawtime);
22801 tm_struct = localtime (&rawtime);
22802
22803 switch(type)
22804 {
22805 case curyear:
22806 {
22807 int32_t year = tm_struct->tm_year + 1900; /* year */
22808 //year format starts at 1900, so we add it to the return
22809 return year;
22810
22811 }
22812 case curmonth:
22813 {
22814 int32_t month = tm_struct->tm_mon +1; /* month */
22815 //Months start at 0, but we want 1->12
22816 return month;
22817 }
22818 case curday_month:
22819 {
22820 int32_t day_month = tm_struct->tm_mday; /* day of the month */
22821 return day_month;
22822 }
22823 case curday_week:
22824 {
22825 int32_t day_week = tm_struct->tm_wday; /* day of the week */
22826 return day_week;
22827 }
22828 case curhour:
22829 {
22830 int32_t hour = tm_struct->tm_hour; /* hours */
22831 return hour;
22832 }
22833 case curminute:
22834 {
22835 int32_t minutes = tm_struct->tm_min; /* minutes */
22836 return minutes;
22837 }
22838 case cursecond:
22839 {
22840 int32_t secs = tm_struct->tm_sec; /* seconds */
22841 return secs;
22842 }
22843 case curdayyear:
22844 {
22845 int32_t day_year = tm_struct->tm_yday; /* day in the year */
22846 return day_year;
22847 }
22848 case curDST:
22849 {
22850 int32_t isDST = tm_struct->tm_isdst; /* daylight saving time */
22851 return isDST;
22852 }
22853 default: return -1;
22854
22855 }
22856 }
22857
22858 extern const char *itemclass_help_string_defaults[itype_max];
22859
22860 /* end */
22861
22862 24576 int32_t FFScript::getQuestHeaderInfo(int32_t type)
22863 {
22864 24576 return quest_format[type];
22865 }
22866
22867 bool isSideViewGravity(int32_t t)
22868 {
22869 return (Map.CurrScr()->flags7&fSIDEVIEW) != 0;
22870 }
22871
22872
22873
22874
22875 void FFScript::ZScriptConsole(bool open)
22876 {
22877
22878
22879 #ifdef _WIN32
22880 if ( console_is_open )
22881 {
22882 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
22883 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
22884 zscript_coloured_console.gotoxy(0,0);
22885 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
22886 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
22887 }
22888 else
22889 {
22890 //close
22891 zscript_coloured_console.Close();
22892 }
22893 #endif
22894 }
22895
22896 template <typename ...Params>
22897 void FFScript::ZScriptConsole(int32_t attributes,const char *format, Params&&... params)
22898 {
22899 #ifdef _WIN32
22900 initConsole();
22901 zscript_coloured_console.cprintf( attributes, format, std::forward<Params>(params)... );
22902 #endif
22903 }
22904
22905 int32_t getpitfall(int32_t x, int32_t y){return 0;}
22906
22907 bool update_hw_pal = false;
22908 void update_hw_screen()
22909 {
22910 if (is_headless())
22911 return;
22912
22913 framecnt++;
22914
22915 zc_process_display_events();
22916 if (update_hw_pal)
22917 {
22918 zc_set_palette(RAMpal);
22919 update_hw_pal = false;
22920 }
22921
22922 render_timer_wait();
22923 render_zq();
22924 }
22925
22926 bool checkCost(int32_t ctr, int32_t amnt)
22927 {
22928 if(!game) return true;
22929 if(amnt <= 0) return true;
22930 switch (ctr)
22931 {
22932 case crMONEY: //rupees
22933 {
22934 if ( current_item_power(itype_wallet) ) return true;
22935 break;
22936 }
22937 case crMAGIC: //magic
22938 {
22939 if (get_qr(qr_ENABLEMAGIC))
22940 {
22941 return (((current_item_power(itype_magicring) > 0)
22942 ? game->get_maxmagic()
22943 : game->get_magic()+game->get_dmagic())>=amnt*game->get_magicdrainrate());
22944 }
22945 return true;
22946 }
22947 case crARROWS:
22948 {
22949 if(current_item_power(itype_quiver))
22950 return true;
22951 if(!get_qr(qr_TRUEARROWS))
22952 return checkCost(crMONEY, amnt);
22953 break;
22954 }
22955 case crBOMBS:
22956 {
22957 if(current_item_power(itype_bombbag))
22958 return true;
22959 break;
22960 }
22961 case crSBOMBS:
22962 {
22963 if(current_item_power(itype_bombbag)
22964 && itemsbuf[current_item_id(itype_bombbag)].flags & item_flag1)
22965 return true;
22966 break;
22967 }
22968 }
22969 return (game->get_counter(ctr)+game->get_dcounter(ctr)>=amnt);
22970 }
22971 bool checkmagiccost(int32_t itemid, bool checkTime)
22972 {
22973 if(itemid < 0)
22974 {
22975 return false;
22976 }
22977 itemdata const& id = itemsbuf[itemid];
22978 return checkCost(id.cost_counter[0], id.cost_amount[0])
22979 && checkCost(id.cost_counter[1], id.cost_amount[1]);
22980 }
22981 bool checkbunny(int32_t itemid)
22982 {
22983 return true;
22984 }
22985
22986 void payCost(int32_t ctr, int32_t amnt, int32_t tmr, bool ignoreTimer)
22987 {
22988 return;
22989 }
22990 void paymagiccost(int32_t itemid, bool ignoreTimer, bool onlyTimer)
22991 {
22992 return;
22993 }
22994 bool is_in_scrolling_region()
22995 {
22996 return false;
22997 }
22998
22999 void enter_sys_pal(){}
23000 void exit_sys_pal(){}
23001
23002 void replay_step_comment(std::string comment) {}
23003 bool replay_is_active() {return false;}
23004 9 bool replay_is_replaying() {return false;}
23005 bool replay_version_check(int min, int max) {return max == -1;}
23006 bool replay_is_debug() {return false;}
23007 std::string replay_get_meta_str(std::string key){return "";}
23008 int32_t item::run_script(int32_t mode){return 0;};
23009 ffcdata* slopes_getFFC(int id)
23010 {
23011 return nullptr;
23012 }
23013
23014 int calculate_test_dmap()
23015 {
23016 int dmap = -1;
23017 auto pal = Map.getcolor();
23018 int scr = Map.getCurrScr();
23019 int scrx = scr & 0x0F;
23020 for(auto q = 0; q < MAXDMAPS; ++q)
23021 {
23022 auto& dm = DMaps[q];
23023 if(dm.map != Map.getCurrMap())
23024 continue;
23025 if((dm.type&dmfTYPE)!=dmOVERW)
23026 {
23027 if(scrx < dm.xoff || scrx >= dm.xoff+8)
23028 continue;
23029 }
23030 if(dmap < 0)
23031 dmap = q; // soft-accept this, but look for better still
23032 if(pal == dm.color)
23033 {
23034 dmap = q;
23035 // found the best match we have information for, break out
23036 break;
23037 }
23038 }
23039 if(dmap < 0) dmap = 0;
23040 return dmap;
23041 }
23042
23043 #ifdef __EMSCRIPTEN__
23044 extern "C" void open_test_mode()
23045 {
23046 int dmap = calculate_test_dmap();
23047 int scr = zc_min(0x7F, Map.getCurrScr());
23048
23049 em_open_test_mode(filepath, dmap, scr, -1);
23050 }
23051
23052 extern "C" void get_shareable_url()
23053 {
23054 EM_ASM({
23055 ZC.setShareableUrl({open: UTF8ToString($0), map: $1, screen: $2});
23056 }, filepath, Map.getCurrMap(), Map.getCurrScr());
23057 }
23058 #endif
23059
23060 11 void setZScriptVersion(int32_t v){}
23061